For In 循环
JavaScript for in 语句循环遍历对象的属性:
语法
for (key in object) {
// code block to be executed
}
实例
const person = {fname:"Bill", lname:"Gates", age:25};
let text = "";
for (let x in person) {
text += person[x];
}
亲自试一试
例子解释
for in 循环遍历 person 对象
每次迭代返回一个键 (x)
键用于访问键的值
键的值为 person[x]