DEV Community

Discussion on: Use this trick to map over single objects in Javascript

Collapse
 
janpauldahlke profile image
jan paul

hm, i just don't get the advantage here. is it synonym to

 return <p> {example.name} </p>
Enter fullscreen mode Exit fullscreen mode
Collapse
 
janpauldahlke profile image
jan paul

i thought array in response is no go, because haacked.com/archive/2008/11/20/ana...

Collapse
 
deaddoctor profile image
deaddoctor

this useful when your response is usually a list of objects and you're using a map to output it, but when your response is a single item it's not in an array, it's just a single object and using map throw an error.

Collapse
 
arikaturika profile image
Arika O • Edited

True, but how do you know if the response from the server has one object inside or an array of objects? You'll need to use different rendering methods (use map or not) depending on what you get from the fetch - so you would still need to make a check somewhere.