When creating an array, I start by finding all the members in the chatbox:
var membersList = $('#chatbox_members' , avacweb_chat.doc.body).find('li');
var onlineUsers = [];
var offLineUsers = [];
for(var i =0;i<membersList.length;i++){
var name = $(membersList[i]).text().replace("@","");
onlineUsers.push(name);
}
alert(onlineUsers);
The resulting onlineUsers
array would look something like this:
[Mr.EasyBB,Tonight,Tomorrow,Gone];
My question arises when using two for loops, one inside a setInterval function and another outside to compare:
var membersList = $('#chatbox_members' , _chat.doc.body).find('li');
var onlineUsers = [];
var offLineUsers= [];
for(var i =0;i<membersList.length;i++){
var name = $(membersList[i]).text().replace("@","");
onlineUsers.push(name);
}
var int = setInterval(function() {
var newMember = ('#chatbox_members' , _chat.doc.body).find('li');
for(var i =0;i<newMember.length;i++){
var name = $(newMember[i]).text().replace("@","");
offLineUsers.push(name);
}
This results in:
onlineUsers = [Mr.EasyBB,Tonight,Tomorrow,Gone];
offLineUsers = [Mr.EasyBB,Tonight];
In order to get the offline users, I want to replace onlineUsers
with offLineUsers
, which should return Tomorrow,Gone
. However, since objects do not have a 'replace' function, how can I achieve this?
I suspect that using the splice function won't work without parameters, and methods such as pop or shift only remove elements from the beginning and end of an array.