iT邦幫忙

2021 iThome 鐵人賽

DAY 18
0
Modern Web

YDKJS 一邊讀 You Don't Know JS Yet 一邊卡關一邊弄懂的日子 ԅ(≖‿≖ԅ)系列 第 18

Day18 - this&Object Prototypes Ch3 Objects - Iteration 開頭

var myArr = ['燃麵', '生菜', '花椒'];
myArr.a = '雉雞';

// 直接取得 value
for (var item of myArr) {
    console.log( item ); // '燃麵', '生菜', '花椒'
}

console.dir(myArr);
// for of 是利用 Object 內建的 @@iterator function,透過其中的 next 方法,去一個一個檢查值與判斷迴圈是否結束
// 作者透過以下手動使用 @@iterator next,讓我們知道過程中發生什麼事
var it = myArr[Symbol.iterator]();
console.dir(it);
console.log(it.next()); // { value:'燃麵', done:false } 
console.log(it.next()); // { value:'生菜', done:false } 
console.log(it.next()); // { value:'花椒', done:false } 
console.log(it.next()); // { done:true }

今天先理解到這邊~如果上述內容有出入,希望路過的朋友能俠義挺身糾正,感恩的心 ԅ(≖‿≖ԅ)


上一篇
Day17 - this&Object Prototypes Ch3 Objects - Iteration 開頭
下一篇
Day19 - this&Object Prototypes Ch3 Objects - Iteration
系列文
YDKJS 一邊讀 You Don't Know JS Yet 一邊卡關一邊弄懂的日子 ԅ(≖‿≖ԅ)30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言