0

I would like to convert array of json objects into single json object.

  const source = [ [{"id":"20210728","item":"Item 1","description":"Details of Item1"},{"id":"20210729","item":"Item 2","description":"Details of Item2"}],[{"id":"20210717","item":"Item 3","description":"Details of Item3"}] ]

I need this to be converted as

 const destination =   [{"id":"20210728","item":"Item 1","description":"Details of Item1"},{"id":"20210728","item":"Item 2","description":"Details of Item2"},{"id":"20210717","item":"Item 3","description":"Details of Item3"}]

Could someone help please? I am a learner of React JS. Please accept my ignorance if it is a silly question. Thanks, Sasi

Andreas
  • 21,535
  • 7
  • 47
  • 56
Sasi C
  • 23
  • 3
  • [There's no such thing as a "JSON object"](http://benalman.com/news/2010/03/theres-no-such-thing-as-a-json/) – Andreas Aug 18 '21 at 09:29
  • You want to "flatten" `source`, hence -> [`Array.prototype.flat()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flat) – Andreas Aug 18 '21 at 09:31

0 Answers0