const initialState =
{
"cartItems": [
{
"itemId": 1,
"quantity": 1
},
{
"itemId": 5,
"quantity": 7
},
{
"itemId": 2,
"quantity": 3
}
]
};
const a = Object.assign({}, initialState, {
cartItems: initialState.cartItems.slice(1)
})
console.log(a)
// 가장 마지막 값으로 덮어지기때문에 잘린값이 최종으로 나타나게 된다.
// {
// cartItems: [
// { itemId: 5, quantity: 7 },
// { itemId: 2, quantity: 3 }
// ]
// }
console.log(initialState)
// {
// cartItems: [
// { itemId: 1, quantity: 1 },
// { itemId: 5, quantity: 7 },
// { itemId: 2, quantity: 3 }
// ]
// }
let state = {notification : [1, 2, 3]}
console.log(Object.assign({}, state, { notification : state.notification.slice(1)}))
// { notification: [ 2, 3 ] }
console.log(Object.assign({}, {notification : [1, 2, 3]}, { notification : state.notification.slice(1)}))
// { notification: [ 2, 3 ] }