i have to update an element in array object based on a condition. currently i am using forEach and based on condition i am applying calculation in that element. i want to know the easiest way to updating the array without for loop
below is my array
[{index:123,total:20,family:'mobile'},
{index:321,total:40,family:'mobile'},
{index:543,total:54,family:'mobile'}]
i want to update total with total*2
for an element with index ‘321’in the above array
my array should look like below after executing logic
[{index:123,total:20,family:'mobile'},
{index:321,total:80,family:'mobile'},
{index:543,total:54,family:'mobile'}]
i am using below code
var selectedId = 321;
this.arrayList.forEach((element, indexval) => {
if((element.index== selectedId){
this.arrayList[indexval].total = element.total*2
}
});
can this be optimized so that i need not iterate the list