简体   繁体   English

jQuery .each()不按预期迭代字符串数组

[英]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 的jsfiddle

Do this, the first parameter is for index: 这样做,第一个参数是索引:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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