I have an array that contains objects with multiple values that could grow from hundreds to thousands of elements that need to be constantly accessed and modified. Something like:
var array = [
{
id: 'someId',
val1: 'someValue',
val2: 'someValue'
},
{...n}
]
In order to change an existing object I'll get it by id while looping through the array
array.forEach(obj => {
if(obj.id == '999'){
obj.value2 = 'someOtherValue'
}
})
I know there are different ways of looping and different methods, for, indexOf, find, etc, I'm not asking which is the best or efficient way, but it seems weird to iterate over a big array that many times.
So, is there another way I could alter a object at a certain location in the array without having to loop every time or it this normal ?