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

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

哪个返回:

TypeError: Object has no method 'each'

我以为我可以以这种方式遍历数组..

4

1 回答 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)

于 2012-11-12T19:16:54.150 回答