Does the .map() method have to be passed an array yeah? It can't be passed an object ?

#Javascript

#AskNostr

Reply to this note

Please Login to reply.

Discussion

Yes, because map is part of Javascript Array built-in function. It's not available for other data type.

https://www.w3schools.com/jsref/jsref_map.asp

Technically you are passing a function that processes each item of the array.

you can call Object.keys to get an array of property names of yourObject and the use the map metod with it:

Object.keys(yourObject).map( key => doStuff(yourObject[key]))