Please check down the code below, I want to push an object multiple times into an array and set a specified path. Hope someone can help. TNX!
To keep it simple I just removed all loops and static addressed my array, but still no success and I don't got any idea why:
wrong result:
let myObject = {
"version": "2.0",
"worker": {
"todo": []
}
};
let myObjectArray = new Array();
myObjectArray.push(myObject);
myObjectArray.push(myObject);
myObjectArray[0]["worker"]["todo"] = "test";
console.log(myObjectArray);
correct result:
let myObjectArray = [
{
"version": "2.0",
"worker": {
"todo": []
}
},
{
"version": "2.0",
"worker": {
"todo": []
}
}
];
myObjectArray[0]["worker"]["todo"] = "test";
console.log(myObjectArray);