Javascript Map multiple values into list

I currently have an array … code goes like this:


var namelist = o => );

This gives me the name of the cars.

What I want to do it to pass several values instead of just one so I get then call for them when needed.

For example id and name.

How can I do this?

Using the ES6 style you may have have a problem doing:

.map(o => {name:, id:})

Because the curly braces mean that you start a block, not an object.
If that is the problem you are having, you should use that block, with a return statement:

.map(o => { return {name:, id:} })

Or, create an object by using the constructor:

.map(o => new Object({name:, id:}))


You can also do:

.map(o => ({name:, id:}))

The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .
Read More:   How to round up to the nearest 100 in JavaScript

Similar Posts