commit
1714051f9a
1 changed files with 1 additions and 1 deletions
|
@ -320,7 +320,7 @@ But that's actually a bad idea. There are potential problems with it:
|
||||||
|
|
||||||
There are so-called "array-like" objects in the browser and in other environments, that *look like arrays*. That is, they have `length` and indexes properties, but they may also have other non-numeric properties and methods, which we usually don't need. The `for..in` loop will list them though. So if we need to work with array-like objects, then these "extra" properties can become a problem.
|
There are so-called "array-like" objects in the browser and in other environments, that *look like arrays*. That is, they have `length` and indexes properties, but they may also have other non-numeric properties and methods, which we usually don't need. The `for..in` loop will list them though. So if we need to work with array-like objects, then these "extra" properties can become a problem.
|
||||||
|
|
||||||
2. The `for..in` loop is optimized for generic objects, not arrays, and thus is 10-100 times slower. Of course, it's still very fast. The speedup may matter only in bottlenecks or just irrelevant. But still we should be aware of the difference.
|
2. The `for..in` loop is optimized for generic objects, not arrays, and thus is 10-100 times slower. Of course, it's still very fast. The speedup may only matter in bottlenecks or seem irrelevant. But still we should be aware of the difference.
|
||||||
|
|
||||||
Generally, we shouldn't use `for..in` for arrays.
|
Generally, we shouldn't use `for..in` for arrays.
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue