I\'m replacing an item in a react state array by using the ... spread syntax. This works:
let newImages = [...this.state.images] newImages[4] = updatedImage this
You can convert the array to objects (the ...array1), replace the item (the [1]:"seven"), then convert it back to an array (Object.values) :
...array1
[1]:"seven"
Object.values
array1 = ["one", "two", "three"]; array2 = Object.values({...array1, [1]:"seven"}); console.log(array1); console.log(array2);