How does the outer array in Javascript know when the inner array has completed its iteration? I am recursively iterating through the array below and would like to understand how the outer function or array can determine when the inner array has finished.
{
"rules": [
{
"id": 1,
"value": "ABC"
},
{
"id": 2,
"value": "PQR"
},
{
"id": 3,
"value": "XYZ"
},
{
"rules": [
{
"id": 10,
"value": "ST"
},
{
"id": 12,
"value": "UI"
}
]
},
{
"id": 5,
"value": "5XYZ"
}
]
}
Using a recursive function to iterate through the array.
The desired output is: ABC, PQR, XYZ, 5XYZ Within Group: ST, UI
Edit1
var message = '';
var infoMessage = getMessageData(false);
function getMessageData(isGroup) {
angular.forEach(rulesArray, function(v, k) {
if (rulesArray.id === undefined) {
message += getMessageData(true);
} else {
message += v.value;
if (isGroup) {
message += 'Within Group: ' + v.value;
}
}
});
}