I am attempting to insert objects into an existing array only if a certain condition is met.
Let me share the code snippet with you:
RequestObj = [{
"parent1": {
"ob1": value,
"ob2": {
"key1": value,
"key2": value
},
},
},
{
"parent2": {
"ob1": value,
"ob2":{
"key1":value,
"key2": value
}
}
}]
In this scenario, I need to include another object in the RequestObj
array based on certain conditions. While I am familiar with using RequestObj.push()
, I am unsure how to add it within the parent1
object.
if (key3 !== null) {
// Include the following object inside parent1 object
"ob3": {
"key1": value,
"key2": value
}
}
Despite my efforts, I have not been able to come up with a solution for this issue. Your assistance would be greatly appreciated.