Replace an element in an array with a new item without modifying the array and return the new value
const fish = [ { name: 'Marlin', weight: 105 }, { name: 'Bass', weight: 8 }, { name: 'Trout', weight: 13 }]const salmon = { name: 'Salmon', weight: 22}replace(fish, salmon, f => f.name === 'Bass') // => [marlin, salmon, trout] Copy
const fish = [ { name: 'Marlin', weight: 105 }, { name: 'Bass', weight: 8 }, { name: 'Trout', weight: 13 }]const salmon = { name: 'Salmon', weight: 22}replace(fish, salmon, f => f.name === 'Bass') // => [marlin, salmon, trout]
Description
Replace an element in an array with a new item without modifying the array and return the new value
Example