7

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

1

1 Answer 1

19

Do this, the first parameter is for index:

$.each(tags, function(index, tag) {  
  console.log(tag);
});
Sign up to request clarification or add additional context in comments.

2 Comments

Oh, hmm...i had no idea the first arg was the index. Thanks.
Or you can just do something like: console.log(tags[tag]);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.