2012-11-12 20 views
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' 

我想我可以通過一個數組這樣循環..

+0

的。每個是一個jQuery對象..你需要使用對象和數組 –

+1

陣列唐」。每個$沒有'each'方法,你在混合jQuery對象和數組。 –

回答

5

你有什麼是迭代的jQuery對象。您應該使用$.each像下面,

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

也在裏面$.each功能params爲(index,value)

+0

非常感謝你爲這個維加 – Trip