Yep. Beat me to it. It's all the difference between having an ownProperty or not.
I'm wondering, since I've never tried to do this and can't conveniently try it right now, what the in operator reports for things like 0 in [,1,2]? Is that statement true or false? Or is it a syntax error?
I went ahead and updated my test gist with an if in test to see what it did.
const slotted = [,,'one'];
let i = 0;
while (i < slotted.length) {
if (i++ in slotted) {
console.log(`${i - 1} is in the array`);
}
}
it, too, will inform us that only an index of 2 exists. This I think further confirms that these items in the array are not "hidden properties" at all.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Yep. Beat me to it. It's all the difference between having an ownProperty or not.
I'm wondering, since I've never tried to do this and can't conveniently try it right now, what the
inoperator reports for things like0 in [,1,2]? Is that statement true or false? Or is it a syntax error?I tested five loops:
for in,for of,forEach,mapandfor ofwas the only one that iterated on all slots.Here's a gist of what I wrote. Feel free to run it in a few different browsers and tell me if my tests were wrong.
I went ahead and updated my test gist with an
if intest to see what it did.it, too, will inform us that only an index of
2exists. This I think further confirms that these items in the array are not "hidden properties" at all.