I have this challenge which in my head seems easy enough, but I can't seem to get my function right.
The challenge is as follows:
Create a function that determines if a given name is amongst the names.
So here is my array and function -
var family = ["Steve", "John", "Dani", "Bob"]; function searchName(f){ for (i=0; i<family.length; i++){ if ((family.lastIndexOf(f) != family[i])) {family[i]} } } searchName("Moe"); Now all this returns is undefined. Which is better than errors I suppose. What I want it to do is when I pass through a name that is not in the array to have it return a false statement, and if a name that is in the array, true. I also know that I need to throw in .toUpperCase and .toLowerCase in there as well to account for the case sensitivity. My assumption is that rather than just an if statement, I need an if/else if/ else.
indexOfwhich already does what you want. It will return -1 if there's no match, or an index greater than or equal to zero if there is. See developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/….alert(["Steve", "John", "Dani", "Bob"].includes("Moe"))alert(/\bMoe\b/.test(["Steve", "John", "Dani", "Bob"]))alert(["Steve", "John", "Dani", "Bob"].some(/./.test, /\bMoe\b/))