Is there a better way to do this?
I have a list of objects.
I want the list has two values: an ID and a NAME.
Both Name & ID are distinct taken separately of together.
{ 'Nam': 'Joe', 'ID' : 1 }
{ 'Nam': 'Mary', 'ID' : 2 }
{ 'Nam': 'Joe', 'ID' : 1 }
{ 'Nam': 'Mary', 'ID' : 2 }
{ 'Nam': 'Biggie', 'ID' : 3 }
{ 'Nam': 'Joe', 'ID' : 1 }
Joe is always 1, Mary 2, Biggie 3, ...
Then end result is to just be:
{ 'Nam': 'Mary', 'ID' : 2 }
{ 'Nam': 'Biggie', 'ID' : 3 }
{ 'Nam': 'Joe', 'ID' : 1 }
.
var rRec = new Array();
rec.reduce(function(a, i) {
if (a.indexOf(i['Nam']) < 0) {
a.push(i['Nam']);
rRec.push({ 'Nam' : i['Nam'], 'Id' : i['Id'] });
}
return a;
}, []);
console.log('rRec', rRec);