About 451,000 results
Open links in new tab
  1. javascript - How to replace item in array? - Stack Overflow

    May 7, 2011 · Well if anyone is interresting on how to replace an object from its index in an array, here's a solution. Find the index of the object by its id: const index = items.map(item => item.id).indexOf(objectId) Replace the object using Object.assign() method: Object.assign(items[index], newValue)

  2. javascript - Replacing objects in array - Stack Overflow

    Jun 2, 2016 · let indexInMasterData = masterData.map(masterDataObj => masterDataObj.id).indexOf(updatedObj.id); // First make an array of IDs, to use indexOf(). // If there is a matching ID (and thus an index), replace the existing object in masterData with the updatedData's object.

  3. javascript - How can I find and update values in an array of objects ...

    You can use findIndex to find the index in the array of the object and replace it as required: var item = {...} var items = [{id:2}, {id:2}, {id:2}]; var foundIndex = items.findIndex(x => x.id == item.id); items[foundIndex] = item;

  4. How to Replace an Object in an Array with Another Object Based …

    Feb 27, 2024 · You can use findIndex() to find the index of the object that matches the desired property, and then use splice() to replace the object at that index with the new object. Example: The below example demonstrates how to replace an object in an array with another object based on a property in JavaScript using findIndex and splice methods.

  5. JavaScriptReplace an Item from JS Array | GeeksforGeeks

    Apr 1, 2025 · The Array Indexing approach replaces an item in an array by directly accessing its position using the index and assigning a new value. This method is straightforward, modifies the original array, and is ideal for known index positions.

  6. How to Replace Object in an Array in JavaScript - Delft Stack

    Feb 2, 2024 · This article demonstrates how to replace an object in an array in JavaScript using the index and splice method with examples.

  7. JavaScript: Update/Replace a Specific Element in an Array

    Mar 22, 2023 · This quick and straightforward article shows you a couple of different ways to update or replace a specific element in an array in modern JavaScript. Using array[index] syntax. You can directly access an element in an array using its index and update its value:

  8. Replace an object in an array with another object in JavaScript

    We can replace an object in an array with another object in JavaScript using splice() method as well as map() method.

  9. How to Replace an Element in an Array in JavaScript

    Mar 1, 2024 · To replace an element in an array, use the `Array.indexOf()` method to get the index of the element. Change the value of the element at the specific index. The value of the array element will get updated in place.

  10. how to replace an element with a specific index in an array of objects

    Aug 24, 2018 · You can assign the new element values to replace the existing one in the array. like: var newElement = {name:"lithe", op: "GE", field:"34545"}; arr[2] = newElement; See demo:

  11. Some results have been removed
Refresh