matt matt - 10 months ago 22
Javascript Question

Checking for duplicate entries in array of objects and creating a new one

I'm trying to merge duplicate entries in an array of objects by creating a new array.

I don't know how to check for duplicated without looping through the new array, which then messes me up when trying to push stuff because it does it every time for the outer loop.

How should I do this properly?

var arr=[0];
for (var k in data) {
var name = data[k].name;
var item = data[k];
//check if already in array
for (var l in arr){
if (arr[l].name == name){
arr[l].value = arr[l.value] + ';;' + item.value;
} else {


With Lodash

var arr = _.uniqBy(data, 'name');