-2

if anyone can help me I will be very grateful =D

How do I convert a set that contains arrays of objects into a single array of objects?

to convert this:

(2) [Array(5), Array(4)]
    0: Array(5)
       0: {id:1, name:"A"}
       1: {id:2, name:"B"}
       2: {id:3, name:"C"}
       3: {id:4, name:"D"}
       4: {id:5, name:"E"}
    1: Array(4)
       0: {id:6, name:"F"}
       1: {id:7, name:"G"}
       2: {id:8, name:"H"}
       3: {id:9, name:"I"}

in that

(1) [Array(9)]
   0: {id:1, name:"A"}
   1: {id:2, name:"B"}
   2: {id:3, name:"C"}
   3: {id:4, name:"D"}
   4: {id:5, name:"E"}
   5: {id:6, name:"F"}
   6: {id:7, name:"G"}
   7: {id:8, name:"H"}
   8: {id:9, name:"I"}
Luh
  • 77
  • 1
  • 5

1 Answers1

0

Apart from flat() mentioned in comments you can use arrays spread syntax:

const arr1 = [1, 2, 3];
const arr2 = ['a', 'b', 'c'];
const merged = [...arr1, ...arr2];
James Jr.
  • 163
  • 6
  • This works, but since the problem specifies that the arrays are elements of an array, you'd have to know ahead of time how many elements it contains, e.g. `[...arr[0], ...arr[1]]` – Codebling Jan 07 '21 at 17:33