Symbol.iterator: IterableIterator<T>;
순회가 가능하면 무엇을 할 수 있나?
const array = [1, 2, 3];
console.log(array.values());
console.log(array.entries());
console.log(array.keys());
//iterator 사용해보기
const iterator = array.values();
while(true){
const item = iterator.next();
if(item.done) break;
console.log(item.value);
}
for(let item of array.values()){
console.log(item);
}
const obj = {id : 123, name : 'yena'}; // obj is not iterable
for(const key in obj) { // obj는 for of 를 사용하지 못함
console.log(key); // 대신, for key -in을 사용하여 받아올 수 있음
}