1

I'm writing a chat app and a function in it checks if a user is logged in or not. When a user logs in, it writes the ID to an array. I have a use a function that can check if a user is logged in to the server, but as an argument you need to give it a user ID, which are contained in the array.

Here's where I'm stuck - If the functions checks to see if the ID is logged in and it determines its not, it returns a value of "false". I'd like to run all of these through the function one after another. How do I then remove that name from the array?

var loggedInUsers = [];
var user = easyrtc.idToName(i); //converts random digits to assigned ID
loggedInUsers.push(user);
easyrtc.getConnectStatus(???)  //Checks if a user is logged in

Thanks!!

Kyle Foley
  • 190
  • 7

2 Answers2

0

use .indexOf method:

loggedInUsers.indexOf(userID) > -1 // user id is in the array
quirimmo
  • 9,800
  • 3
  • 30
  • 45
0

If you want to remove that user from the loggedInUsers array, Try removing it with splice.

loggedInUsers.splice(i, 1);

Here i is index of user ID chech here for splice

optimistanoop
  • 912
  • 1
  • 11
  • 14