Your conditional statement checks if the records does have a ‘tracks’ property. Also, you also need to be more specific as you’re checking the property of a particular record (i.e. you need to include the id field). Finally, you’re creating an array but not pushing any value to it.
No. You have correctly accessed properties within records in other parts of your code, with records[id][prop]. However, if you want to check if a particular record has a particular property in the first place, you first access the record (records[id]) and then check if it has the property, using hasOwnProperty() as you did.
Whenever you want to reverse a condition (e.g. to check that a record doesn’t have a specific property), you can just negate the expression by prefixing it with !.
EXAMPLE:
if (a == 1) {
return 'yes'
}
…and the reverse
if (!a == 1) {
return 'no'
}
…which could also be written as
if (a != 1) {
return 'no'
}
The first type of negation is extremely useful in cases where the second isn’t valid (as in your case above).