I want to push a key-value pair in the 1st element
Like this
updatedPlatingProcs = [{
"data":{
"AsfTime":1,
"newKey":"newValue" -- // this is where I wanna add the new key-value pair
},
"data2":{
"Asf":3
}
}]
I tried something like this
var platingTimeVal = {
PlatingTime: processArea * time,
};
updatedPlatingProcs[0]["data"].push(platingTimeVal);
updatedPlatingProcs.push(platingTimeVal); // also this
Got wrong results
1 Answer 1
Your error is that data in updatedPlatingProcs[0]["data"] is not an array, it is an object.
You can set a value of that object like so:
updatedPlatingProcs[0].data.PlatingTime = processArea * time;
answered Jul 20, 2021 at 6:48
coagmano
5,6801 gold badge31 silver badges42 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
lang-js
updatedPlatingProcs[0]["data"]is an Object, not an Array. You can not use thepushmethod on an Object. ThisupdatedPlatingProcs.push(platingTimeVal);should actually work.