var ages = [];
for (var person in byName){
if (typeof byName[person.mother] != "undefined")
ages.push(ageDifference(person));
}
console.log(ages);
It is this particular code that will not work. I know the function ageDifference
works. The line believed to be the issue is the if condition not functioning as I intend it to:
function ageDifference(person){
var ageDiff = person.born - byName[person.mother].born;
return ageDiff;
}
byName
is a name mapped object with multiple properties, the only 2 of which are relevant being born
and mother
. Ie:
{
name: "Philibert Haverbeke"
sex: "m"
born: 1907
died: 1997
father: "Emile Haverbeke"
mother: "Emma de Milliano"
}
I am trying to build an array of all of the age differences between people and their mother. As some of them have mothers specified in the mother property who don't exist as objects in the enclosing object, the loop should skip to the next iteration when it is on these people. This appears to be the sticking point, as when I run the code as is nothing gets pushed to the array, and if I take the condition out I expectedly receive an error more or less saying when object is passed to ageDifference there is no such property born of the stated object (because that object DOESN'T EXIST!).