The other day I had this typical thing to do in my function:

Find a favorite with a certain id, and attach notifications to it.


The solution (one of the possible solutions) is to find the index with findIndex method and then manipulate the object in the original array of objects with that index:

// this.favorites is an array of Favorite objects
// Notification has a favoriteId identifier
const foundIndex = this.favorites.findIndex((favorite: Favorite) => === notification.favoriteId);
if (foundIndex > -1) this.favorites[foundIndex].notifications = notification;



Saved you some valuable time?

Buy me a drink ๐Ÿบ