Javascript number of object by different property values in array -
best way count number of objects in array different object property p values.
function([{"p":"a"},{"p":"b"},{"p":"a"}]){ // code } // in case return 2
you can use array.prototype.filter() keep values want. in case, must create variable temp
storing duplicate values , within filter function
returns true
if not exist in case. have new array of unique values.
var arr = [{"p":"a"},{"p":"b"},{"p":"a"}], temp = []; var arruniques = arr.filter(function(obj){ return temp.indexof(obj.p) === -1 ? !!temp.push(obj.p) : false }); alert(arruniques.length)
Comments
Post a Comment