I have an existing empty array parentChildQuestions=[]. I'd like to add to it to build the following structure:
[
{
"id": "001",
"childQuestions": [
"002",
"003"
]
}
]
I have the following function but the childQuestions property doesn't seem to be adding. My log isn't showing it at all.
function addToDependentQuestions (thisQuestion) {
if (parentChildQuestions.length===0) {
var thisParent = parentChildQuestions.push({"id":thisQuestion.Parent_Question__c});
thisParent.childQuestions=[thisQuestion.Id];
console.log(thisParent.childQuestions);
}
else {
var foundParentQuestion = $.grep(parentChildQuestions, function(e) {
return parentChildQuestions.Id == thisQuestion.Id;
});
foundParentQuestion.childQuestions.push(thisQuestion.Id);
}
console.log('parentChildQuestions' + JSON.stringify(parentChildQuestions));
}