CHAPTER 12. 이터레이터와 제너레이터
이터레이터의 특징
1) next() 메소드
const book = [
"Twinkle, twinkle, little star",
"How I wonder what you are",
"Up above the world so high",
"Like a diamond in the sky",
"Twinkle, twinkle little star",
"How I wonder what you are"
];
const it = book.values(); // 이터레이터 생성
console.log(it.next()); // {value: "Twinkle, twinkle, little star", done: false}
console.log(it.next()); // {value: "How I wonder what you are", done: false}
console.log(it.next()); // {value: "Up above the world so high", done: false}
console.log(it.next()); // {value: "Like a diamond in the sky", done: false}
console.log(it.next()); // {value: "Twinkle, twinkle little star", done: false}
console.log(it.next()); // {value: "How I wonder what you are", done: false}
console.log(it.next()); // {value: undefined, done: true}
console.log(it.next()); // {value: undefined, done: true}
console.log(it.next()); // {value: undefined, done: true}
console.log(it.next()); // {value: undefined, done: true}2) 독립적
Last updated