簡體   English   中英

通過字符串數組迭代的語法有什么問題?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM