I am trying to push new data in a secondary array using javascript in React but I am unable to do it.
I have my object declared as this:
const {
id,
user,
task
} = documentTask;
const {
time,
duration,
sum
} = task;
And then I am trying to push a value to the task field from another class.
tasksWithOverallValues.push({
duration: overallSeconds,
sum: overallPrice
});
tasksWithOverallValues is a list of documentTask's.
When I am doing what is shown .push({duration... then the object becomes undefined.
My idea was to call :
tasksWithOverallValues.push({
task.duration: overallSeconds,
task.sum: overallPrice
});
Because my it is trying to push the values into an unkown list, but I get the following error:
'task' is not defined no-undef
After that is done the object becomes undefined and I cannot do anything with it.
So my question is, how can I push new values into a secondary list?
task.duration/sum"? Can you share an example of what you are trying to do and what error you got?