I have an array of objects as follows on my JS server side:
[
{
"Company": "IBM"
},
{
"Person": "ACORD LOMA"
},
{
"Company": "IBM"
},
{
"Company": "MSFT"
},
{
"Place": "New York"
}
]
I need to iterate over this structure, detect any duplicates, and then create a duplicate count next to each value.
Both values must match to qualify as a duplicate, for example. Company: IBM is not suitable for Company: MSFT.
I have options for changing the incoming array of objects, if necessary. I would like the result to be an object, but I'm really trying to get it to work.
EDIT: Here is the code that I still have, where processArray is an array, as stated above.
var returnObj = {};
for(var x=0; x < processArray.length; x++){
returnObj[processArray[x]] = returnObj[processArray[x]] || processArray[x].toString();
returnObj[processArray[x]].count = returnObj[processArray[x]].count || 1;
returnObj[processArray[x]].count = returnObj[processArray[x]].count + 1;
}
console.log('====================' + JSON.stringify(returnObj));
source
share