Jak*_*ake 0 javascript google-chrome-extension
I'm working on a chrome extension and I'm using a lot of if statements to check the webpage for a list of words. And I have to continuously type each word over and over again but I'm wondering if there was a way to check the words one time through a list.
Currently I'm kinda working like this:
if (text == "apple")
if (text == "orange")
if (text == "Banana")
if (text == "Cherry")
if (text == "Lime")
Run Code Online (Sandbox Code Playgroud)
and so on.. But is there a way to check a list of these words so I don't have so many if statements?
I was thinking of something like this:
List = "apple", "orange", "Banana", "Cherry", "Lime"
if (text == "list")
Run Code Online (Sandbox Code Playgroud)
谷歌Chrome扩展程序是否可以这样?
将您的单词列表放入数组中,然后您可以使用indexOf进行简单的操作.例如:
var list = ["apple", "orange", "Banana", "Cherry", "Lime"];
Run Code Online (Sandbox Code Playgroud)
然后你可以检查列表:(感谢@Edwin使它更短)
if(list.indexOf(text));
Run Code Online (Sandbox Code Playgroud)