最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - jQuery .each() not iterating over array of strings as expected - Stack Overflow

programmeradmin2浏览0评论

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

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

Share Improve this question asked Jan 10, 2013 at 6:38 AyushAyush 42.5k51 gold badges167 silver badges241 bronze badges 1
  • here you go api.jquery.com/jQuery.each – NullPoiиteя Commented Jan 10, 2013 at 6:51
Add a comment  | 

1 Answer 1

Reset to default 19

Do this, the first parameter is for index:

$.each(tags, function(index, tag) {  
  console.log(tag);
});
发布评论

评论列表(0)

  1. 暂无评论