In Javascript: The Final Guide to the Sixth Edition of David Flanagan on page 147, the author discusses the caveat when repeating through an array with a for..in loop: the following quote (bold mine)
... For this reason, you should not use a for / in loop in an array if you include an additional test to filter out unwanted properties. You can use any of these tests :
for(var i in a) {
if (!a.hasOwnProperty(i)) continue;
}
for(var i in a) {
if (String(Math.floor(Math.abs(Number(i)))) !== i) continue;
}
Now the first code fragment is clear to me, the inherited properties will be skipped.
However, the second code fragment is not entirely clear to me.
As far as I understand, the second code fragment will skip any non-numeric property of the array (regardless of whether it is its own property or not (unlike the first code fragment))
, :
if (Number(i) != i) continue;
, ?
- ?