How to create list of arrays using map?

  • A+
Category:Languages

Suppose I have this array of object:

let arr =  [    { id: "1"},    { id: "2"},    { id: "3"} ] 

I would create a list of arrays, so I tried:

arr.map(x => x.id); 

but this will return:

["1", "2", "3"] 

I want an array for each value, eg: ["1"] ["2"] ["3"]

 


If you want an array of each then do

arr.map(x=>[x.id]); 

Comment

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: