'How do I loop through the search results and based on which ids match return true to display different info for it?

so I am trying to search through the search results and see who already exists in the friendRequest array of the user searching. If they exist then I want to change the button that displays for the user to Contact requested and disable it.

Here is my code on the route file:

exports.searchPost = function(req, res, err) {
  User.find({$or:[
      {firstName: req.body.firstName},
      {lastName: req.body.lastName},
      {email: req.body.email},
      {phone: req.body.phone}]
  }, function(err, users, userAdd) {
    if(err) {

      return res.render('searchError', {title: 'Weblio'});
    } else {

      if(req.body.firstName=== '' && req.body.lastName==='' && req.body.email==='' && req.body.phone=== '') {
        //maybe  a diff page saying that is not a valid search page
        return res.render('searchError', {title: 'Weblio'});
      } else {
        console.log('addman');
        console.log(userAdd);
        console.log(users);
        for(x in users) {

          User.findById(req.signedCookies.userid,
            {friendRequest: x.id}
          if(x.id === true ) {
            console.log('addman1');
            return userAdd = false;
          } else {
            console.log('addman2');
            return userAdd = true;
          }

        });
        console.log(x);
      }
      console.log(userAdd);
      console.log(users);
      //can use this loop if want to serve the info as oppose to doing it in jade, just change users to uuser
      /*var i = 0;
      var uuser = [];
      for(i=0; i < users.length; i++) { 

        uuser.push(users[i].firstName + ' ' +  users[i].lastName);
      };
      */
      //console.log(i);
      return res.render('searchResults', {title: 'Weblio',
        usersFound: users,
        userAdded: userAdd
      });
    }
  }
});
};

Here is the jade file:

extends layout
block content   
    div
    legend Search Results
    div#userResults
    for user in usersFound 
        a(href='/user/#{user.id}')
            p #{user.firstName} #{user.lastName}
        - if(userAdded === false)
            button.addContact(data-user=user.id) Add Contact
        - else
            button.addContact(data-user=user.id, 'disabled'='disabled') Contact Requested


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source