2

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?

1
  • 1
    It's not correct to use the in operator in this situation. in checks whether an object has a certain property name. Commented Dec 3, 2013 at 16:03

1 Answer 1

3
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
    }
}
Sign up to request clarification or add additional context in comments.

2 Comments

then do i need to nest an if statement within this as if(-1) then continue?
@user2811419: No. The condition of the if statement evaluates to true if the element is not in the array.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.