-3
(2) [Array(2), Array(1)]
0: Array(2)
0: {_id: '61cd4544264332414823198d', action: 'checkin', time: '2021-12-30T05:36:04.143Z'}
1: {_id: '61cd60713082f35340af2a87', action: 'checkout', time: '2021-12-30T07:32:01.986Z'}
length: 2
[[Prototype]]: Array(0)
1: Array(1)
0: {_id: '61cd455a26433241482319a5', action: 'checkin', time: '2021-12-30T05:36:26.346Z'}
length: 1
[[Prototype]]: Array(0)
length: 2
[[Prototype]]: Array(0)

I want all objects into one array like :

[
0: {_id: '61cd4544264332414823198d', action: 'checkin', time: '2021-12-30T05:36:04.143Z'}
1: {_id: '61cd60713082f35340af2a87', action: 'checkout', time: '2021-12-30T07:32:01.986Z'}
2: {_id: '61cd455a26433241482319a5', action: 'checkin', time: '2021-12-30T05:36:26.346Z'}
]
pilchard
  • 12,414
  • 5
  • 11
  • 23
  • 1
    Try [`.flat()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flat) – cbr Dec 30 '21 at 11:15

1 Answers1

0

You can try this:

const input = [[{_id: '61cd4544264332414823198d', action: 'checkin', time: '2021-12-30T05:36:04.143Z'},
{_id: '61cd60713082f35340af2a87', action: 'checkout', time: '2021-12-30T07:32:01.986Z'}], [{_id: '61cd455a26433241482319a5', action: 'checkin', time: '2021-12-30T05:36:26.346Z'}]];

console.log(input.flat());
// output: > Array [Object { _id: "61cd4544264332414823198d", action: "checkin", time: "2021-12-30T05:36:04.143Z" }, Object { _id: "61cd60713082f35340af2a87", action: "checkout", time: "2021-12-30T07:32:01.986Z" }, Object { _id: "61cd455a26433241482319a5", action: "checkin", time: "2021-12-30T05:36:26.346Z" }]

Viettel Solutions
  • 1,519
  • 11
  • 22