I am in the process of identifying unique records based on their ID and including the corresponding names with the following code. By replacing the if
statement with:
if (p.indexOf(c.ID) < 0) p.push(c.ID);
This will generate an array with unique IDs, but my goal is to also include the person's name in the final array. I attempted to adjust the if statement accordingly, however, I encountered issues where p[1] was not initialized initially, leading to unexpected behavior in the reduce function. How can I modify the code below to achieve the desired outcome?
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;
}, []);
};