Constructor
new PeekableArrayIterator(array, start)
Constructor
Example
source = [0, 1, 2, 3, 4, 5];
// also quite helpful for document.querySelector(...)
itr = new utils.array.PeekableArrayIterator(source);
console.log(itr.next()); // { done: false, value: 0 }
//-- peek without moving the iterator
const peekItr = itr.peek();
console.log(peekItr.next()); // { done: false, value: 1 }
console.log(peekItr.next()); // { done: false, value: 2 }
console.log(peekItr.next()); // { done: false, value: 3 }
console.log(peekItr.next()); // { done: false, value: 4 }
console.log(peekItr.next()); // { done: true, value: 5 }
//-- move the main iterator
console.log(itr.next()); // { done: false, value: 1 }
Of course, for each will always work
or
for (let i of new utils.array.PeekableArrayIterator(list)) {
console.log(i);
}
// 1\n2\n3\n4\n5
Parameters:
Name | Type | Description |
---|---|---|
array |
Iterable | something we can iterate over |
start |
Number | the starting index |