I am using an object in my react-redux app in reducer file.The object is like as below
tradings: {
'buy': {
data: []
},
'sell': {
data: []
},
'total': {
data: []
}
},
So,whenever i get a new dataset i want to push it into data array of any object ,Suppose i got buy and data:[time:234234, amount: 0.0123 ].So my new tradings object will look like this:
tradings: {
'buy': {
data: [[time:234234, amount: 0.0123 ], ....]
},
'sell': {
data: []
},
'total': {
data: []
}
},
How can i concat arrays into this array in object?
array1.concat(array2)?tradings.buy.data.push(yourData);ortradings[key].data.push(yourData);wherekeyis a string var[time:234234, amount: 0.0123 ]is not a valid array in JS. It should be an object if you want key-value pairs like{time:234234, amount: 0.0123 }. Why not usingArray.push()btw? Maybe withswitch/caseto act based on buy/sell type?pushcan't be used here unless you make a copy before, as the question is related to redux you need to keep care of mutablitytradings.buy.data = [...tradings.buy.data, newData]may help