for...in 循环:只能获得对象的键名,不能获得键值
var arr = ['red', 'green', 'blue'] for(let item in arr){ console.log(item) }
for...of 循环:允许遍历获得键值
var arr = ['red', 'green', 'blue'] for(let item of arr){ console.log(item) }
2024-02-05 10:42:52
for...in 循环:只能获得对象的键名,不能获得键值
var arr = ['red', 'green', 'blue'] for(let item in arr){ console.log(item) }
for...of 循环:允许遍历获得键值
var arr = ['red', 'green', 'blue'] for(let item of arr){ console.log(item) }