Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

find unique objects in an array of objects in javascript 5

var array = [{"name":"Joe", "age":17}, {"name":"Bob", "age":17}, {"name":"Carl", "age": 35}];
var unique = [];
var distinct = [];
for(var i = 0; i < array.length; i++ ){
  if(!unique[array[i].age]){
    distinct.push(array[i]);
    unique[array[i].age] = 1;
  }
}


gs.info(distinct);
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #find #unique #objects #array #objects #javascript
ADD COMMENT
Topic
Name
5+5 =