抱歉,这可能很简单,但让我感到难过。我试图遍历这个数组并注销每个值,但脚本正在注销一个字符串对象。
propertiesToSanitize = ["title", "description", "place_name"]
$.each propertiesToSanitize, ->
console.log this
转换为 jQuery 为
var propertiesToSanitize;
propertiesToSanitize = ["title", "description", "place_name"];
$.each(propertiesToSanitize, function() {
return console.log(this);
});
正在返回:
String
0: "t"
1: "i"
2: "t"
3: "l"
4: "e"
length: 5
知道为什么它返回这个而不只是“标题”或任何其他值吗?在此先感谢您的帮助。
最佳答案
每次迭代的索引和值作为回调中的参数提供。
$.each(propertiesToSanitize, function(index,value) {
console.log(index + ':' + value);
});
关于javascript - 数组 .each() 循环返回字符串而不是 jQuery 中的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10369085/