跳轉到內容

JavaScript/保留字/in

來自華夏公益教科書,自由的教科書
上一個: import 保留字 下一個: instanceof

Thein關鍵字

[編輯 | 編輯原始碼]

Thein關鍵字用於更簡潔的表示for迴圈。

程式碼
  var numbers = [2, 3, 5, 7, 10, 11], result = 1;

  for (number in numbers) {
    result += number;
    console.log("result = " + result);

    if (result%2 == 0) {
      continue;
    }

    if (result > 20) {
      break;
    }
  }
返回以下結果
result = 3
result = 6
result = 11
result = 18
result = 28
result = 39


另請參閱

[編輯 | 編輯原始碼]
上一個: import 保留字 下一個: instanceof
華夏公益教科書