-4
I need to check if a name exists inside the array and return true
if you find or false
otherwise.
let names = ["Ana","João","Pedro","Maria"];
function hasName() {
for (let i=0; i < names.length;i++) {
if (names === "Pedro") {
return true;
}
}
}
Welcome to [en.so]. Remember to always add a description to your post making it explicit what your difficulty is and what you’ve tried. Also note that you can use code formatting using the formatting bar while writing the post. This makes the post easier to read and understand and consequently will help you to have an answer.
– Jéf Bueno
After you finish doing this one read exercise on that link: Determining whether an array contains a certain element
– Augusto Vasques
Enjoy and see also about other methods like find, some, Every.
– LeAndrade