javascript - Generator Function with existing array -
i have object array numbers id values.
i want generate new id's or return ones object array.
how can using generator function , yield?
example tried:
var array = [{'id': 0}, {'id': 2}, {'id': 3}]; function* idmaker() { var index = 0; array.foreach(object => { console.log(object.id); }); while (index => o) yield index++; } var gen = idmaker(); console.log(gen.next().value); // 0 console.log(gen.next().value); // 1 console.log(gen.next().value); // 2 console.log(gen.next().value); // 3 console.log(gen.next().value); // 4
Comments
Post a Comment