代码:
let obj = {
name: 'zs',
stus:['zs1','zs2','zs3','zs4'],
[Symbol.iterator](){
let index = 0
return {
next: () => {
if(index < this.stus.length){
const result = {value:this.stus[index],done:false}
index++;
return result
}else{
return {value: undefined,done:true}
}
}
}
}
}
for(let v of obj){
console.log(v);
}