0

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]

4

1 Answer 1

3

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]);
Sign up to request clarification or add additional context in comments.

1 Comment

This gave an array of array: [[1][2]]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.