I'm working with a huge Array of data, for this question I will write something similar avoiding all the key / value.
There is an Array of Objects:
[
{ id: 0, name: 'Tom', age: '18' },
{ id: 1, name: 'Rob', age: '22' },
{ id: 2, name: 'Carl', age: '19' },
...
]
Sometimes the user is added or updated and via SSE and I receive back a response of that user object.
What I need is to check if the user is already in the array checking by id
. Because if the user has been added I need to do a few actions but if it is just updated I need to do a few others...
Basically what I need is something like: if user.id is in array.user do something, else do something else...
What I tried so far is a for loop, but I don't think it is a good idea, or maybe I used it badly.