[Solved] How can an array containing objects be restructured in a preferred format?


You could use Object.values and map. Use Computed property names to create the desired object

let foobar = [{"foo":{"title":"example title foo","desc":"example description foo"}},{"bar":{"title":"example title bar","unnecessary":"this is not needed","desc":"example description bar"}}]

let output = foobar.map(a => {
  let { title, desc } = Object.values(a)[0];
  return { How can an array containing objects be restructured in a preferred format? : desc }
})

console.log(output)

1

solved How can an array containing objects be restructured in a preferred format?