I want the function to be able to output true or false, if the searchElement exists in the array it should return true or false. I know i could make use of a simple for loop and if-else combination but i want to make use of arrow function.
I know by default 'includes' function exists in js, i am exactly trying to make a function similar to it, that's why i don't want 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);
This line alone provides me with the arrayElement, I want it to return true or false, that's why i tried the if else statement but i don't know how to include that code-block in the arrow function line, and i think === should have returned true or false instead of the number itself, plz let me know what i am doing wrong, thanks
const result=somestuff.filter(arrayElement=> arrayElement===searchElement)