I have an array of Objects.
{projectId:10,projectName:design,status:done},
{projectId:11,projectName:code,status:onGoing}
Now, this array is coming from an API call and its dynamic.
I want to insert an item, {time:30} into the first object in the array.
That is, into the object with the index 0.
So, the output will be like this.
{projectId:10,projectName:design,status:done,time:30},
{projectId:11,projectName:code,status:onGoing}
I have tried the following code:
let projects = [{projectId:10,projectName:design,status:done},
{projectId:11,projectName:code,status:onGoing} ];
let newArray = projects.slice();
newArray[0].push({ time: '30' });
console.log(newArray);
But the above code is giving me the following error.
TypeError: newArray[0].push is not a function
Can you help me out with this problem. Thanks,