javascript - Iterating over an array of objects -
i want iterate on array of objects in order oldest person , youngest person. how that? looks easy task, there no way can ages simple each loop. ideas?
var p = [ { name : "billy", age : 5 }, { name : "lucy", age : 31 }, { name : "jonny", age : 11 }, { name : "wolfgang", age : 78 }, { name : "robert", age : 23 } ];
i have seen this didn't me in understanding problem.
simple loop
var high = 0, low; //start @ 0 index, iterate until array length, iterate 1 (var = 0; < p.length; i++) { //checking high if (p[i].age > high) high = p[i].age; //checking low if (p[i].age < low || low == null) low = p[i].age; }
Comments
Post a Comment