I have a simple array in React's state, consisting of only integers:
this.state = {
myArray: [1,2,3]
}
I'm trying to replace a value in an immutable way (value 2 should be replaced by 8):
const valueToReplace = 2
const newValue = 8
const myArray = this.state.myArray
const arrayPosition = myArray.indexOf(valueToReplace)
const newArray = Object.assign([], myArray, {arrayPosition: newValue})
this.setState({myArray: newArray})
But my way doesn't change myArray in state. I think I'm not using Object.assign in the correct way.