tin
4/20/2019 - 7:50 PM

Convert array of objects to single object

Convert array of objects to single object

let arrayToObject = (arr) => {
  return arr.reduce(
		(obj, item) => Object.assign(obj, { ...item }),
		{}
	);
}


let arr = [
  {
    "01": ["google.com", "github.com"]
  },
  {
    "02": ["stackoverflow.com"]
  },
  {
    "03": ["nodejs.com"]
  }
];

console.log(arrayToObject(arr));
// {
//   "01": ["google.com", "github.com"],
//   "02": ["stackoverflow.com"],
//   "03": ["nodejs.com"]
// }