1

Imagine you have this :


[[{id: 1}], [{id: 2}]]

Is posible to convert the previous array in something like this? :

[{id:1}, {id:2}]

2 Answers 2

3

You can simply use Array.prototype.flat for that:

console.log([
  [{
    id: 1
  }],
  [{
    id: 2
  }]
].flat());

Sign up to request clarification or add additional context in comments.

Comments

2

One way is:

console.log([[{id: 1}], [{id: 2}]].map(arr => arr[0]))

Another way is Array.prototype.flat():

const arr1 = [[{id: 1}], [{id: 2}]]

console.log(arr1.flat())

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.