How to check if a list contains a string in javascript? -
this question has answer here:
how can test if string "orange" without quotes, exists in list such 1 below, using javascript?
var suggestionlist = ["apple", "orange", "kiwi"];
edit: question different "how check if array.." because newbies me don't know list of items @ first glance "array". newbies going search term "list".
indexof() default use in such cases.
if( suggestionlist.indexof("orange") > -1 ) { console.log("success"); }
.indexof() returns position in array (or string) of found element. when no elements found returns -1
.
Comments
Post a Comment