Here is the code:
var state = {
txn:[],
do:false
}
var newState = Object.assign ({}, state,
{
txn: state.txn.slice(0,0).concat([{txnId:3, b:5}, {txnId:5, b:6}])
},
{
do: !state.do
}
);
var newState2 = Object.assign ({}, newState,
{
txn[0].txnId: 9
});
The first Object.assign works and the newState has the txn array filled with two elements.
The second Object.assign is not working.
It says that "[" is an unexpected token.
Any suggestions?
txn, it's a key in an object, not a variable, it has to benewState.txntxnin the first one, you set a key with that name, and usestate.txn, never justtxn