I\'m trying to match values from an array to a variable string. So if, for example, I have an array and a variable :
var array = [\'Potato\', \'Cheese\', \'Bikin
Try this. You have to loop the array and match array elements with the given string
var array = ['Potato', 'Cheese', 'Bikini', 'Truck', 'Express'];
var something = 'Potato Thief';
for (var i = 0; i < array.length; i++) {
if(something.search(array[i]) == 0){
console.log(true);
}else{
console.log(false);
}
}
you don't need an if statement for it
return array.indexOf(something)!=-1
I would do this like as follows;
var array = ['Potato', 'Cheese', 'Bikini', 'Truck', 'Express'],
something = 'Potato Thief',
test = array.some(e => something.includes(e));
console.log(test)