deepSearchObject(obj) {
let duplicateExists = false;
Object.keys(obj).forEach(key => {
if(key === 'fieldCode') {
let value = obj[key]
if(this.fieldCodes.includes(value)) {
duplicateExists = true;
return;
} else {
this.fieldCodes.push(value);
}
}
if (typeof obj[key] === 'object') {
this.deepSearchObject(obj[key])
}
})
console.log('RETURN VALUE', duplicateExists);
return duplicateExists;
},
Ideally I want to return from deepSearchObject when a duplicate is found, no more reason to traverse the object, currently instead of returning on the last line, the code above will log out the return value of True and then continue to execute, why? I've broken out of the loop with the return, do I need something else to break out of recursion?