How React render an Array Object

I am working on cloning Ravenous project. I have a function (code below):

renderSortByOptions() {
     return Object.keys(sortByOptions).map(option => { 
          return <li key={sortByOptions[option]}>{option}</li>; 

I consoled what map() return and it’s object (???). I go to MDN page and they said that what map() returns is an array.
Then I wrote this code to render a list to view:

<div className="SearchBar-sort-options">

I have no idea how React can render an array like that.
In conclusion, I have 2 questions:

  1. map() return an object or an array?
  2. How React render an array or an object?
    Thank you for your support. I’m trying to improve my English skills so if you feel I didn’t show any respect, I just wouldn’t mean that.

There’s your array. What is being mapped?

It’s an array of string. I used map to cover them in li tags with unique key for each element.

If you use typeof on an array it will return 'object'. To check if an object is an array we use,

1 Like

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.