As per the MDN documentation:

A for...in loop does not iterate over non–enumerable properties.
Objects created from built–in constructors like Array and Object have
inherited non–enumerable properties from Object.prototype and
String.protottype that are not enumerable, such as String's indexOf
method or Object's toString method. The loop will iterate over all
enumerable properties of the object or that it inherits from its
constructor's proptotype (including any which overwrite built-in
properties).

On Nov 1, 1:31 pm, Amit Agarwal <[email protected]> wrote:
>  var arr = new Array(1,2,3,4)
> [1, 2, 3, 4]
>
>  for(a in arr){
> console.log(a, arr[a])}
>
> 0 1
>  1 2
>  2 3
>  3 4
>
> for-in loop is known to be slower than other loops because it also looks up
> in the prototype chain. Why doesn't for-in loop prints all the available
> properties and methods for the array in this case?
>
> -Amit Agarwal

-- 
To view archived discussions from the original JSMentors Mailman list: 
http://www.mail-archive.com/[email protected]/

To search via a non-Google archive, visit here: 
http://www.mail-archive.com/[email protected]/

To unsubscribe from this group, send email to
[email protected]

Reply via email to