如何在javascript中更改函数单击时对象属性的值?

如何在javascript中更改函数单击时对象属性的值?,javascript,angular,Javascript,Angular,员工=[{Id:1001,工资:2000},{Id:1002,工资:1000}] 预期结果:-我正在浏览器上显示上述阵列。在函数单击时,我希望工资乘以12。即年薪应显示在网页上。但是,在函数单击时,我使用数组的map()乘以工资,然后将新计算的年薪推送到salary属性中 实际结果:-新计算的salary属性未被推入students数组的属性中 代码片段:- map() { this.annualSalary = this.students.map(a => a.Salary *

员工=[{Id:1001,工资:2000},{Id:1002,工资:1000}]

预期结果:-我正在浏览器上显示上述阵列。在函数单击时,我希望工资乘以12。即年薪应显示在网页上。但是,在函数单击时,我使用数组的map()乘以工资,然后将新计算的年薪推送到salary属性中

实际结果:-新计算的salary属性未被推入students数组的属性中

代码片段:-

map() {
    this.annualSalary = this.students.map(a => a.Salary *  12 );
    this.annualSalary.forEach((as, index) => {
      let asalary = as;   
      this.students.push({

        Salary : asalary,
      });

    });
这是你的解决方案

    for (let index = 0; index < this.students.length; index++) {
      const element = this.students[index];
      this.students[index].Salary = element.Salary * 12
    }
for(让index=0;index
我想使用数组的map()和foreach()。但是这个操作不需要使用两个循环,这也会影响性能,但是如果我想使用foreach而不是for循环呢?我没有使用2个循环。。Map是一个数组函数这里是使用forEach
this.students.forEach(element=>{element.Salary=element.Salary*12;})的解决方案在这种情况下不需要使用map()?