JSFiddle - React, Tailwind, and code Playground

by Vikram Deshmukh

JavaScript

const temp = [
	{key: "facebook", value: 123},
  {key: "facebook", value: 123},
  {key: "facebook", value: 123},
  {key: "twitter", value: 123},
  {key: "web", value: 123}
];
const final = temp.reduce((acc,d)=> {
	if(!acc[d.key]) acc[d.key] = 0;
  acc[d.key] += d.value
  return acc;
}, {});

console.log(final)