Javascript modify array

Viewed 1745

If I have an array that look like this:

[
   {
       key: some_key,
       payload: { ... }
   }, 
   {
       key: some_key,
       payload: { ... }
   }, 
   {
       key: some_key,
       payload: { ... }
   }, 
   ...
]

and I want to find something using a key and then modify the payload.

Is there any way other than iterating through the array?

I have several concerns about iterating

  1. This array is used by many async functions, I am worried that the index might be invalidated by some other functions during the iteration.
  2. Iteration might lead to a lower performance.

I thought about using a immutable object there, but converting to array before every re-rendering doesn't seem very efficient.

Any good idea?

6 Answers
Related