title: How to change a value inside array of object in Redux
body: <p>I have stored an array of object in Redux State and inside each object there is a key named price. Now when I increment the quantity button I need to access the object that has the key inside redux and change the price value. I was able to do that but it's not working properly the price is being changed but a new object is being added in the state of Redux you can see it in the screenshot below. hope I was able to explain the problem clearly. if not please let know so I can explain more.</p>
  <p><a href="https://i.stack.imgur.com/kHSvX.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/kHSvX.gif" alt="enter image description here" /></a></p>
  <p>Cart Component</p>
  <pre><code>increment(e, item){
    let qty = e.target.previousElementSibling.textContent;
    qty++;
    e.target.previousElementSibling.textContent = qty;
    this.props.changePrice(item);
  }
  
  &lt;div&gt;
    &lt;input onClick={(e) =&gt;this.decrement(e)} type=&quot;submit&quot; value=&quot;-&quot;/&gt;
    &lt;span&gt;1&lt;/span&gt;
    &lt;input onClick={(e) =&gt; this.increment(e, item)} type=&quot;submit&quot; value=&quot;+&quot;/&gt;
  &lt;/div&gt;
  
  function mapStateToProps(state){
     return({
       itemlist: state.rootReducer
     })
   }
  function mapDispatchToProps(dispatch) {
     return({
        removeItem: (item)=&gt;{
          dispatch({type: 'removeCart', payload: item})
        },
        changePrice: (item)=&gt;{
          dispatch({type: 'changePrice', payload: item})
        }
     })
   }
  export default connect(mapStateToProps, mapDispatchToProps)(Cart);
  </code></pre>
  <p>Reducer Component</p>
  <pre><code>const changePrice = (itemArray, item)=&gt;{
    let newObject = {};
    let filteredObject = itemArray.filter(reduxItem =&gt; reduxItem.id === item.id);
    let newprice = filteredObject[0].price + filteredObject[0].price;
    filteredObject[0].price = newprice;
    newObject = filteredObject;
    const something = ([...itemArray, newObject]);
    return something;
  }
  const reducer = (state = [], action) =&gt;{
    switch (action.type) {
      case 'Add':
        return [...state, action.payload]
      case 'removeCart':
        const targetItemIndex = state.indexOf(action.payload);
        return state.filter((item, index) =&gt; index !== targetItemIndex)
      case 'changePrice':
           return changePrice(state, action.payload)
      default:
        return state;
    }
  }
  export default reducer;
  </code></pre>