Currently, I am grappling with a dilemma on how to determine if within a deeply nested JSON object, featuring numerous unknown arrays and properties, lies a specific property that goes by the name "isInvalid". My objective is to identify this property and, if its value is true, return false.
var checkValidity = function (data) {
for (var property in data) {
if (data.hasOwnProperty(property)) {
if (property == "isInvalid" && data[property] === true) {
return false;
}
else {
if (typeof data[property] === "object" && data[property] !== null) {
this.checkValidity(data[property]);
}
}
}
}
};
The code snippet provided above is what I have been experimenting with, but unfortunately, it has not yielded the expected results. I did attempt to explore the capabilities of underscore as well, but couldn't locate the necessary functions. Does anyone have any suggestions or ideas? (Please refrain from suggesting regular expressions)