07-24-2023, 12:31 AM
My state object looks like this:
const [result,setResult] = useState({
series: [
{
name: 'Budget',
data: [5000, 3000, 5000, 7000, 6000, 4000]
},
{
name: 'Income',
data: [8000, 1000, 7000, 2000, 5000, 3000]
}
]
})
Now I want to append some data to the `data` array in the first `series` object
{
name: 'Budget',
data: [5000, 3000, 5000, 7000, 6000, 4000]
}
I try to do so with:
function addNumber(){
setResult([...result.series[0].data,45])
}
But it doesn't work. Are there any suggestions or solutions?
const [result,setResult] = useState({
series: [
{
name: 'Budget',
data: [5000, 3000, 5000, 7000, 6000, 4000]
},
{
name: 'Income',
data: [8000, 1000, 7000, 2000, 5000, 3000]
}
]
})
Now I want to append some data to the `data` array in the first `series` object
{
name: 'Budget',
data: [5000, 3000, 5000, 7000, 6000, 4000]
}
I try to do so with:
function addNumber(){
setResult([...result.series[0].data,45])
}
But it doesn't work. Are there any suggestions or solutions?