I have an array of such objects:
var array = [
{"name": "one", "value": .33},
{"name": "one", "value": .54},
{"name": "one", "value": undefined},
{"name": "two", "value": .3},
{"name": "two", "value": undefined},
{"name": "two", "value": undefined},
{"name": "three", "value": undefined},
{"name": "three", "value": undefined},
{"name": "three", "value": undefined},
];
And I need to be able to see if any unique name (one / two / three) has only one number of its properties βvalueβ. Thus, in this example, the answer is Yes, because the property values ββare two:. 3, undefined, undefined.
I have a good way to get unique "name" fields into an array:
function Names(a) {
var temp = {};
for (var i = 0; i < a.length; i++)
temp[a[i].name] = true;
var r = [];
for (var k in temp)
r.push(k);
return r;
}
nameArray = Names(array);
But when I start looking at the cycle, I start to get confused. Just by writing this, I would have thought it would be like this:
var count = 0;
for (objects with name == i){
if (isNaN(value) == false){
count++
if(count > 1) {
return true;
}
}
}
Of course, this is pseudo-code, and perhaps not even the right direction. Any help is appreciated, thanks for reading!