I have array and i searching for the biggest age value with the key
, but after i found it i need to find the next one by exclude the parent of first one from search. Here is array and function example:
//Data
data = {"people":
[{"male": [
{"name": "Bob" ,"age": "32"},
{"name":"Mike", "age":"31"}
]},
{"female": [
{"name":"Jessica", "age": "24"},
{"name":"Ann", "age": "23"}
]}]}
// Function
var age = 0;
data["people"].forEach(function(item) {
for (var key in item) {
if (item.hasOwnProperty(key)) {
item[key].forEach(function(person) {
if (person.age > age) {
age = person.age;
}
});
}
}
});
So based on this example i need get 24
from female
. Please give me some advices.