I want to check if a string in an array has only a certain word.
var nonessential = function(){
for (var i=0; i < arr.length; i++){
var stringnumber = arr[i];
if (stringnumber.indexOf("the")>-1 || stringnumber.indexOf("this")>-1 || stringnumber.indexOf("than")>-1 || stringnumber.indexOf("a")>-1){
}else{
essential = arr.slice(i,1)
console.log(essential)
}
}
So, for example, if the array was ["hey","man","a","this"], I want the new array (essential) to be ["hey","man"]. The problem is, because the indexOf checks for a, so it eliminates "man". I only want to eliminate the array value if the string is ONLY "a", not it if includes it. Any solutions?
indexOfwhen you want simple string equality? Use==.