Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create list of arrays using map?

Tags:

javascript

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"]

like image 564
sfarzoso Avatar asked Nov 29 '22 21:11

sfarzoso


1 Answers

If you want an array of each then do

arr.map(x=>[x.id]);
like image 167
Euan Smith Avatar answered Dec 05 '22 13:12

Euan Smith