Update a Specific Object in an Array (by ID or condition)
If you're working with an array of objects and want to modify just one item based on a condition (like id), use .map() to create a new array where only the matched item is updated — all others stay untouched.
JavaScript doesn't have a built-in spread way to remove a property, but you can use object destructuring to omit a property cleanly.
const user = { id: 1, name: "Jakkrit", online: true };const { online, ...userWithoutOnline } = user;console.log(user); // still has online (untouched)console.log(userWithoutOnline); // online is gone here
It extracts the online property from the user object.
It collects the rest of the properties (everything except online) into a new object called userWithoutOnline.
Super useful when you want to send or store an object without certain fields like removing password before sending to the client.
Add a New Object to an Array
When working with a list of objects (like tasks, users, posts), you often need to add a new one. Use the spread operator to create a new array with the added object.