[英]What is wrong with my syntax iterating through an array of strings?
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'
我以為可以這樣迭代數組。
您擁有的用於迭代jQuery對象。 您應該使用$.each
如下所示,
// index----v v-----value
$.each(array_of_strings, function(i, val) { console.log(val) });
$.each
函數中的參數也是(index,value)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.