Cómo construir mi propio iterador
// Iterador que empieza sobre el índice indicado como parámetro
// ¿Por qué yield?
Array.prototype.myIterator = function* (startIdx = 0) {
while (startIdx < this.length) {
if (this.hasOwnProperty(startIdx)) {
yield [this[startIdx], startIdx];
}
startIdx++;
}
};
// Forma de usarlo
// empieza a iterar en el índice 1
for (var [val, idx] of [0,2,4,6,8].myIterator(1)) {
console.log(val, idx);
}