在JavaScript数组访问不同的元素 [英] Accessing different elements in a javascript array
本文介绍了在JavaScript数组访问不同的元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在叫Ignore.json忽略列表的文件名
[
乔治,
卡尔
]
该文件称为ignore.json
在我的计划,我把文件读入忽略变量
VAR忽略;忽略=要求(./ Ignore.json);
现在我想看看我的数组元素不在该列表那么如果它不在该列表输出code。
我知道如何检查元素是否在数组中,如:
对(列表中的列表){ 如果(名单[名单] .to.toLowerCase()的忽略){
但是,如果我要检查,这是不是列表中,什么是相反的,在JavaScript的?
解决方案
VAR名单,我;
对于(i = 0; I< lists.length;我++){
清单列出= [I]
如果(ignore.indexOf(名单[名单] .to.toLowerCase())=== -1){
// -1表示项目不在列表
}
}
I have names in an ignore list file called Ignore.json
[
"George",
"Carl"
]
The file is called ignore.json
In my program I am reading the file into the ignore variable
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?
解决方案
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
}
}
这篇关于在JavaScript数组访问不同的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文