0 votes
1 view
in Web Technology by (47.7k points)

I've been told not to use for...in with arrays in JavaScript. Why not?

1 Answer

0 votes
by (107k points)

Why we say the for-in statement is a "bad practice" is because it can be misused, for example, to iterate over arrays or array-like objects.

So, the main purpose of the for-in statement is to enumerate over object properties. This statement will go up in the prototype chain, also enumerating over inherited properties, a thing that sometimes is not desired.

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...