I found this snippet in some documentation. Is the if
statement redundant?
for (var key in contactData) {
if (contactData.hasOwnProperty(key)) {
// Omitted
}
}
I tried this out in my browser console and both for
loops printed out the same thing.
contactData = {};
contactData.a = 1;
contactData.b = 2;
for (var key in contactData) {
if (contactData.hasOwnProperty(key)) {
console.log(key);
}
}
for (var key in contactData) {
console.log(key);
}