如何检查传入nameSearch的参数是否与names数组中的最后一项匹配?
function nameSearch(name) {
var names = ["lopi", "aja", "lombo", "dakes", "polq", "kinto", "lufe"];
var i = 0;
while (i < names.length) {
if (names[i] !== name) {
console.log("The current name is " + names[i]);
if (name === names.indexOf(names.length - 1)) { //option one,did not work
if (name === names.indexOf("lufe")) { //option two hard coded,still did not work
console.log("This is the last name in the directory");
}
} else {
console.log("We found " + names[i] + " he is number " + i);
break;
}
i++;
}
}
nameSearch("lufe");