简体   繁体   English

访问JavaScript数组中的不同元素

[英]Accessing different elements in a javascript array

I have names in an ignore list file called Ignore.json 我在名为Ignore.json的忽略列表文件中有名称

[
"George",
"Carl"
]

The file is called ignore.json 该文件称为ignore.json

In my program I am reading the file into the ignore variable 在我的程序中,我正在将文件读取到ignore变量中

var ignore;

ignore = require("./Ignore.json");

Now I want to see if my array element is not in that list then if it is not in that list output the code. 现在,我想查看我的数组元素是否不在该列表中,如果它不在该列表中,则输出代码。

I know how to check if an element is in an array like: 我知道如何检查元素是否在数组中,如:

for (list in lists) {

        if(lists[list].to.toLowerCase() in ignore){

But if I want to check that it is not "in" the list, what is the opposite of in in javascript? 但是,如果我要检查它是否不在列表中,那么javascript中in的反义词是什么?

var list, i;
for(i=0;i<lists.length;i++){
    list = lists[i];
    if(ignore.indexOf(lists[list].to.toLowerCase()) === -1){
        // -1 indicates item was not in list
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM