为什么这个 forEach 代码片段在 AngularJS 中无效?

Why is this forEach code snippet invalid in AngularJS?

这里我有一个通用的计算函数

private calculateTotal(order: InventoryOrder):number{
  let total = 0.0;
  if(order && order.currentInventory){
    order.currentInventory.forEach(x =>{
      console.log(x.quantity);
      console.log("helloworld");
    }  //error appears here<- "," expected.
  } return total;
}

我在 https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach

测试了非常相似的代码
    const array1 = ['a', 'b', 'c'];
    
    array1.forEach(element => {
                    console.log(element);
                    console.log("helloworld");
                              });

// expected output: "a"
// expected output: "b"
// expected output: "c"

知道发生了什么吗?

private calculateTotal(order: InventoryOrder):number{
    let total = 0.0;
    if(order && order.currentInventory){
        order.currentInventory.forEach(x =>{
            console.log(x.quantity);
            console.log("helloworld");
        });
    } 
    return total;
}