-1

I have data as below:

  [ { propertyId: '3257', amenityId: '98' } ],
  [ { propertyId: '3258', amenityId: '98' } ],
  [ { propertyId: '3259', amenityId: '98' } ],
  [ { propertyId: '3260', amenityId: '98' } ],
  [ { propertyId: '3261', amenityId: '98' } ],
  [ { propertyId: '3262', amenityId: '98' } ],
  [ { propertyId: '3263', amenityId: '98' } ],
  [ { propertyId: '3264', amenityId: '98' } ],
  [ { propertyId: '3265', amenityId: '98' } ],
  [ { propertyId: '3266', amenityId: '98' } ]

expect: 


[
    { propertyId: '3257', amenityId: '98' },
    { propertyId: '3258', amenityId: '98' }
    …......................
]

Thank beforehand.

Sok Chanty
  • 1,678
  • 2
  • 12
  • 22

1 Answers1

0

If you're targeting a newer version of JS that supports this, you could simply use:

const flattenedArray = myMultiDimArray.flat()

Otherwise, you could achieve this with a simple reducer:

const flattenedArray = myMultiDimArray.reduce((acc, curr) => {
    acc.push(...curr)
    return acc;
}, [])
Sean Anglim
  • 179
  • 10