I'm trying to get the function loop()
to return true
or return false
after it's done checking if values in one array are present in another array. I'm stuck with where the return statements have to go since I'm new to javascript.
aa = ["one", "two", "three", 'four'];
ab = ["one", "two", "three"];
loop = function() {
aa.forEach(function(i) {
if(!ab.includes(i)) {
console.log (i + ' does not exists in ab')
// return false
} else {
console.log (i + ' exists in ab')
}
});
}
console.log(loop()) // should return false since 'four' is not included in ab
Right now loop()
returns undefined
. How does this have to be done to make loop()
return true or false?