TypeScript - 陣列 forEach()



forEach() 方法為陣列中的每個元素呼叫一個函式。

語法

array.forEach(callback[, thisObject]);

引數詳情

  • callback − 用於測試每個元素的函式。

  • thisObject − 在執行回撥時用作 this 的物件。

返回值

返回建立的陣列。

示例

let num = [7, 8, 9];
num.forEach(function (value) {
  console.log(value);
}); 

編譯後,它將生成以下 JavaScript 程式碼:

var num = [7, 8, 9];
num.forEach(function (value) {
    console.log(value);
});

其輸出如下:

7
8
9
typescript_arrays.htm
廣告
© . All rights reserved.