简体   繁体   中英

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)  })

Which returns :

TypeError: Object has no method 'each'

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

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM