case ActionTypes.ADD_TO_CART: { var newOrders = state.cartItems.slice(); let updatedIem = state.cartItems.find(i => { if (i.id === action.product.id) { return action.product } else { return null } }); if (updatedIem) { var oldOrder = newOrders[action.itemIndex]; var newOrder = Object.assign({}, oldOrder); if (action.direction == 1 && newOrder.quantity > 0) { newOrder.qty++; newOrder.quantity--; } else if (action.direction == -1 && newOrder.qty != 0 && newOrder.quantity > 0) { newOrder.qty--; newOrder.quantity++; } else null newOrders[action.itemIndex] = newOrder; } else { newOrders[action.itemIndex] = action.product } return { ...state, cartItems: newOrders, }; }
this gives me an array(cartItems) of the object but the problem here it's back with another index undefined it's similar to [{first object}, undefined,{third object}]so I don't wanna see undefined I know that the newOrders[theIndex] doing that but I don't find the solution to that or how I should replace this logic