I'm facing a challenge with a JSON array of objects that contains other arrays of objects. The structure of this array is not fixed, making it difficult for me to delete specific elements like
delete mainArray[0].obj.subobj[1].objToOmit;
In my program, I need to exclude a key/object named possibleAnswers
. While transferring the contents of one array to another, I must ensure that the possibleAnswers
object is not included.
Is there a function or method that can help me search through an array of objects and omit the necessary key? What would be your solution?
Example :
Here is a minimal example:
Edit: In the above JSON there is a key called possibleMembers
which is wrong. its possibleAnswers
var collectObservationsFromConceptSets = function () {
$scope.consultation.observations = [];
_.each($scope.consultation.selectedObsTemplates, function (conceptSetSection) {
if (conceptSetSection.observations) {
_.each(conceptSetSection.observations, function (obs) {
$scope.consultation.observations.push(obs);
});
}
});
}
While pushing the object into another array in the code above, how can I exclude the possibleAnswers
keys? Is there a way to do this?
Thank you all for your assistance! Both answers provided are correct and yield the expected output. However, I can only select one answer as correct, and it will be chosen randomly.