Reputation: 566
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?
Upvotes: 0
Views: 91
Reputation: 139
Assuming you have the following object:
tradings = {
'buy': {
data: []
},
'sell': {
data: []
},
'total': {
data: []
}
}
And your received data was:
data = {buy: {time:234234, amount: 0.0123 }}
You'll first need to grab the key in your data
object and then push it to the desired array in your tradings
object like the following:
key = Object.keys(data)[0];
tradings[key].data.push(data[key]);
fiddle: https://jsfiddle.net/9hsvd5pk/
Upvotes: 1
Reputation: 3871
tradings["buy"].data.push( YOUR ARRAY HERE )
to add arrays into that array, or create the array somewhere and add it via javascript :
tradings["buy"].data = YOUR ARRAY HERE
Upvotes: 0