How can I clear the current position after the for loop or after I used .next()
method ?
const arr = [1,4,2];
for(v of arr){
// console.log(v); // 1 4 2
}
// console.log(arr.next()) //arr.next is not a function
/*
*
* Why? because it is an iterable not an iterator,
* and to be able to use .next we need to call the iterator method
* this iterable’s Symbol.iterator returns:
* */
const iter = arr[Symbol.iterator]();
console.log(iter.next());
console.log(iter.next());
console.log(iter.next());
console.log(iter.next());
After this I want get 1 value from item.
How to do this ?
This example is from http://blog.dubizzle.com/boilerroom/2017/01/09/introduction-javascript-iterables-iterators-generators/