function myIterator(arr){
let index = 0;
return {
next: function(){
if(index < arr.length){
return {
value: arr[index++],
done: false
}
}else{
return {
value: undefined,
done: true
}
}
}
}
}
let iter = myIterator([1,2,3,4]);
console.log(iter.next());
console.log(iter.next());
console.log(iter.next());
console.log(iter.next());
console.log(iter.next());
console.log(iter.next());
09-20
357
05-30
115