2
array_of_strings = ["this", "is", "my", "array", "of", "strings"]

array_of_strings.each(function(val, i) {  console.log(i)  })

Which returns :

TypeError: Object has no method 'each'

I thought I could iterate through an array this way..

2
  • the .each is for a jQuery objects.. you need to use $.each for objects and arrays Commented Nov 12, 2012 at 19:18
  • 1
    Arrays don't have an each method, you're mixing jQuery objects and arrays. Commented Nov 12, 2012 at 19:18

1 Answer 1

5

What you have is for iterating jQuery objects. You should use $.each like below,

//                       index----v   v-----value
$.each(array_of_strings, function(i, val) {  console.log(val)  });

Also the params inside $.each function is (index,value)

Sign up to request clarification or add additional context in comments.

Comments

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.