Question: Trying to update one element of an array in this.state I'm getting an (expected ,) error but cant see where I've gone wrong. Do I need to create a temporary array update that, then assign the whole array back to the state

This is essentially what I have

```
this.state = { array: ['a', 'b', 'c'] };

onBack() {
  this.setState({
      array[2]: 'something' 
  });
}

```

Answer: 
You can't update the state like this.

> 
> Never mutate this.state directly, as calling setState() afterwards may replace the mutation you made. Treat this.state as if it were immutable.
> 
> 
> 

Read [React docs](https://reactjs.org/docs/react-component.html#state).

You can do something like this :

```
let newArray = [...this.state.array];
newArray[2] = 'somethingElse';
this.setState({array: newArray});

```

The above example is using [Spread Syntax](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax).

There are multiple ways to modify state, but all the ways should ensure that data is treated as immutable. You can read more about handling state in React [here](https://medium.freecodecamp.org/handling-state-in-react-four-immutable-approaches-to-consider-d1f5c00249d5)
Manoj's answer will work, there is another way using the updater function *(funtinal `setState`)* for `setState` (which you can read about [here](https://reactjs.org/docs/react-component.html#setstate "setState"))

```js
onBack() {
  this.setState(prevState => {
    let newArray = prevState.array
    newArray[2] = "something"
    return { array: newArray }
  });
}

```