我有这段使用 javascript 的代码:
var arr = [
'one',
'two',
'three',
'four',
'five'
];
for (var property1 in arr) {
console.log(property1);
}
当我执行这段代码时,我得到:
'1'
'2'
'3'
'4'
但我想要这个:
'one',
'two',
'three',
'four',
'five'
我如何使用循环来做到这一点?
非常感谢!
最佳答案
使用for..of喜欢关注
var arr = [
'one',
'two',
'three',
'four',
'five'
];
for(var property1 of arr) {
console.log(property1);
}
关于javascript - 如何使用 Django 从 Javascript 获取变量的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55868791/