Cannot read property 'Symbol(Symbol.iterator)' of undefined

The only answer here is that you didn't use "function", so your "this" is not your "users". This would work:

Array.prototype.any = function(comparator) {
    for(let item of this){
        if(comparator(item)){
            return true;
        }
    }
    return false;
};

And then, of course, just use "some".


Using Array.prototype.any() was unnecesary as I was using mongoose to get the users so I changed it to have mongoose try to get a single user that has the secified username and checking if that was defined. Like:

const checkUniqueUserName = (user, res, done) => {
    User.findOne({"userName": user.userName}, (err, foundUser) => {
        if(err){
            res.sendStatus(500);
            console.log(err);
        }

        else if(foundUser){
            res.status(400).send('Username already in use');
        }

        else{
            done(user);
        }
    });
};