javascript - For loop in array reads 'remove'? -


this question has answer here:

i experienced strangest thing, code i'm using :

for (iter in data.list) {     console.log(iter); } 

as expect, log should give number of each row (0, 1, 2...), instead gives me :

0 1 2 remove 

knowing array has 3 rows

did ever encountred ?

basically, problem iterating through array using for in loop, not meant iteratung through arrays. intent iterate through properties of object, , apparently there property called remove on array.

for more details on why for in bad idea when comes arrays, see why using "for...in" array iteration bad idea?.

as solution, i'd suggest use indexed for loop. type of loop not care properties, hence fine. comes down classical:

for (var = 0; < data.list; i++) {   console.log(data.list[i]); } 

by way: should not uppercase in javascript, unless it's constructor function. hence should data.list.

ps: nice read when comes arrays , (mis-)using them, read fun javascript arrays, quite read.


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -