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

Popular posts from this blog

Django REST Framework perform_create: You cannot call `.save()` after accessing `serializer.data` -

Why does Go error when trying to marshal this JSON? -