I am aiming to create a function that can provide either true or false based on whether the searchElement exists in the array. While I could achieve this with a simple for loop and if-else statement, my goal is to utilize an arrow function.
Although JavaScript already has an 'includes' function, I want to create a similar function from scratch which is why I prefer not to use it.
const somestuff=[1,2,54,23,65,132,76,'A','wth','Health is Wealth'];
function includes(array,searchElement){
const result=somestuff.filter(arrayElement=> arrayElement===searchElement)
if(arrayElement===searchElement){
console.log('true');
}
else{
console.log('false');
}
}
includes(somestuff,65);
While the code above successfully identifies the arrayElement, I need it to return true or false instead. This is why I attempted using the if-else statement within the arrow function line, but I am unsure how to incorporate that. Additionally, using === should have returned true or false instead of the number itself. Please advise me on what I might be doing incorrectly, thank you
const result=somestuff.filter(arrayElement=> arrayElement===searchElement)