0

There is an array that contains arrays of objects.

Before

const data = [
  [{ a: "a" }, { b: "b" }, { c: "c" }],
  [{ d: "d" }, { e: "e" }, { f: "f" }],
  [{ g: "g" }, { h: "h" }, { i: "i" }],
];

Could you please suggest the way to convert it to this object?

After

const data = {
  a: "a",
  b: "b",
  c: "c",
  d: "d",
  e: "e",
  f: "f",
  g: "g",
  h: "h",
  i: "i",
};
2
  • you want to make the change in place ... on a const? you wont' be able to change a const Array to a const Object Commented Sep 9, 2022 at 2:00
  • 1
    const y = data.flat().reduce((a,c)=> ({...a, ...c}),{}); console.log(y); Commented Sep 9, 2022 at 3:57

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.