Reputation: 1905
How do I split an array into individual array: [1,2,3,4,5] => [1][2][3][4][5]
The array of objects is gotten from a backend API
const arr = [
{
id: '1',
name: 'Emmanuel',
...
},
{
id: '1',
name: 'Emmanuel',
...
}
]
Doing arr.map(a => a.id)
gave me [1,2,...]
, now how do I get individual array from the ids: [1][2]
Upvotes: 0
Views: 49
Reputation: 386560
Just wrap the return value in an array and take a destructuring assignment into own targets.
let [t1, t2, t3, t4, t5] = arr.map(a => [a.id]);
Upvotes: 3