socket.io变量检查

Okay so basically I have a variable in ajax which I want to send to my socket.io server to check if the variable is already in a json array.

Ajax:

function isUniqueEmail(email) {
    //email checking script here
    $.get('info/mailcheck.js' + email, function(response) {
        if(response == 1) {
            alert("Your email is already on our list");
        }

        else {
            alert("We will add you shortly");
        };      
    })
};

the json array:

{"mail":
[
    "tom@gmail.com",
    "fred@gmail.com",
    "bob@gmail.com"
]}

The socket.io part is where im confused. Basically it just needs to take the variable (an email) check if it is already in the array and return a 1 if it is or return a zero if not and write it in the array.

I don't know much about node.js but you could use a function a bit like the following to check if a value is in an array and push the value to it if it is not.

function pushToArray(value, array) {
    function inArray(val, arr) {
        for (var i=0; i<arr.length; i++) {
            if (arr[i] == val) {
                 return true;
            } 
        return false;
    }
    if (inArray(value, array) {
        return 1;
    } else {
        array.push(value);
        return 0;
    }
}

Are you confused about how to get this to work with socket.io or just how to find the element in the array? If you're using node.js, just use the array.indexOf method:

//obj = {"mail": ["mail1@foo.com", "mail2@baz.com"]}
if (obj.mail.indexOf(email) != -1) {
  //We have your email!
}
else {
  //We don't
}