Opaque way to check your own properties

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; // Skip inherited properties
   // loop body here
}

for(var i in a) {
   // Skip i if it is not a non-negative integer
   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;

, ?

- ?

+4
1

, , :

:

var a = [1, 2, 3];
a['1.5'] = 'busted';
for(var i in a) {
    if (Number(i) != i) continue;
    document.getElementById('output1').textContent += i + '\n';
}
for(var i in a) {
    if (String(Math.floor(Math.abs(Number(i)))) !== i) continue;
    document.getElementById('output2').textContent += i + '\n';
}
<h3>Number(i) != i</h3>
<pre id="output1"></pre>
<h3>String(Math.floor(Math.abs(Number(i)))) !== i</h3>
<pre id="output2"></pre>

:

var a = [1, 2, 3];
a['-5'] = 'busted';
for(var i in a) {
    if (Number(i) != i) continue;
    document.getElementById('output1').textContent += i + '\n';
}
for(var i in a) {
    if (String(Math.floor(Math.abs(Number(i)))) !== i) continue;
    document.getElementById('output2').textContent += i + '\n';
}
<h3>Number(i) != i</h3>
<pre id="output1"></pre>
<h3>String(Math.floor(Math.abs(Number(i)))) !== i</h3>
<pre id="output2"></pre>

, Math.abs Math.floor.

, for for . .

+2

Source: https://habr.com/ru/post/1617882/