I have the following function
function findNeedle(array) {
array.forEach(element => {
if(element === 'needle') {
console.log('needle') // needle
return 'needle'
}
});
}
const needle = findNeedle(['hay', 'junk', 'hay', 'hay', 'moreJunk', 'needle', 'randomJunk'])
console.log(needle)
I don't really understand why my function returns undefined. I tried using forEach and I still have the same issue. The strange thing is that the console.log statement before return 'needle' executes