简体   繁体   中英

jQuery .each() not iterating over array of strings as expected

Doing:

var tags = ["foobar", "hello", "world"];

$.each(tags, function(tag) {  
  console.log(tag);
});

Gives me an output of

0    
1   
2

Why is my output not

foobar   
hello    
world

JSFiddle

Do this, the first parameter is for index:

$.each(tags, function(index, tag) {  
  console.log(tag);
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM