> For the complete documentation index, see [llms.txt](https://omalab.gitbook.io/engineeringwiki/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://omalab.gitbook.io/engineeringwiki/code/javascript/reducer-updating-an-array-with-item-in-middle.md).

# Reducer Updating an Array with Item in Middle

When you need to update an item in the middle of an array, you do this:

```
  switch(action.type) {
    case 'INCREMENT_LIKES' : 
      console.log('incrementing');
      const i = action.index;
      const length = state.length;
      return [
        ...state.slice(0,1),
        {...state[i], likes: state[i].likes + 1},
        ...state.slice(i + length)
      ]
    default:
      return state;
  }
}
```
