I am trying to find get unique records by their ID including the name with the code most below and if I replace the if statement with:
if (p.indexOf(c.ID) < 0) p.push(c.ID);
it will create an array with unique IDs, but I want my final array to also have person's name so I modified the if statement, but then p[1] is not initialized for the first time and the reduce function doesn't run as expected. How do I correctly change the code below to work for what I want?
var arrayUnique = function(a) {
return a.reduce(function(p, c) {
if (p[1].indexOf(c.ID) < 0) p.push([c.person, c.ID]);
return p;
}, []);
};