Answer the question
In order to leave comments, you need to log in
What is the point of an object iterator?
Hello, I'm learning js, I've reached the topic of object iterators. I understand how the code works:
let nam = {
from: 1,
to: 5
}
nam[Symbol.iterator] = function(){
return {
current: this.from,
last: this.to,
next(){
if(this.current <= this.last){
return {
done:false,
value: this.current++
}
}else{
return {done: true}
}
}
}
}
for(let x of nam){console.log(x)}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question