I have a JSON object :
[{"box":1,"parent":[],"child":[{"boxId":2}]},{"box":2,"parent":[{"boxId":1}],"child":[]}]
I have a requirement where in I would like to check whether my JSON object has particular box; if yes then check if it has particular child.
eg: check if box 1 exists
if yes then
check if it has child
if yes then
check if it has child boxId=2
How do I do that in javascript/ jquery?
This is how I tried:
var DependantArr=myJSON;
var $hasDependancy;
DependantArr.map(function (boxes) {
if (boxes.box == 2) {
if (boxes.child.length != 0) {
boxes.child.map(function (child) {
$hasDependancy = true;
return false;
});
}
}
This doesn't seem to work as even after I return false it still continues to go in loop. I would like to break the loop if i find a match.
Any suggestion?
.map(). As thereturnis for the current callback, not the entire operation.