I am looking to include a shared property in my JSON Object. Below is an example of the JSON object:
data = [
{
COUNTRY: 'USA',
POPULATION: 300,
},
{
COUNTRY: 'USA',
POPULATION: 50,
},
{
COUNTRY: 'Canada',
POPULATION: 80,
},
{
COUNTRY: 'USA',
POPULATION: 60,
},
{
COUNTRY: 'Mexico',
POPULATION: 20,
},
{
COUNTRY: 'Mexico',
POPULATION: 40,
},
{
COUNTRY: 'Canada',
POPULATION: 10,
},
];
The desired output is to add POPULATION field for recurring COUNTRY properties as shown below:
data = [
{
COUNTRY: 'USA',
POPULATION: 410,
},
{
COUNTRY: 'Canada',
POPULATION: 90,
},
{
COUNTRY: 'Mexico',
POPULATION: 60,
},
];