I have an array which contains the following items:
var jobName = getNextJobName();
var Details = getNextJobDetails();
var item = {
Name: jobName,
Details: Details
};
array.push(item);
I want to extract all the unique names (from the Name field).
(in order to create a new object which groups all the details for a specific job).
Could you please show me an efficient way to do this?
You mean have a list of those objects, and you want to extract all the unique values?
Here’s a pretty efficient way, storing the values as keys of a new object called
uniqand the value being an array of the ‘Details’ element.http://jsfiddle.net/lmatteis/8LWMH/4/