0

Ok so I am trying to create an Array with my data, because the way I was doing before was giving me some issues.

Code I am trying now

var frame=$('#avacweb_chat iframe');
 var uName=  $('.online-users li',frame.contents());
   var listedUsers = [];
  for(var i =0;i<uName.length;i++){
    var name = $(uName[i]).text();
     listedUsers = [name];
   }
    alert(listedUsers);

Code I have now is

 var membersList = $('.online-users li' , frame.contents()).text().replace("@","").trim();
 var memberUpdate = setInterval(function() {
 var newMember = $('.online-users li' , frame.contents()).text().replace("@","").trim();
if(membersList.length <= newMember.length) {
  var list= membersList.replace(newMember,"");
   alert(list);
 }

Then I have an alert, though it alerts like this

 `User1User2User3`

I want it to alert each time per say,

User1 User2 User3

So I figured if I made it an array it would be easier. though I am not positive on how I'd alert it like so after the array???

1 Answer 1

2

Try changing this line:

listedUsers = [name];

to this:

listedUsers.push(name);

https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/push

If you want to later alert these names one-by-one:

for ( var j = 0; j < listedUsers.length; j++ ) {
    alert( listedUsers[ j ] );
}
Sign up to request clarification or add additional context in comments.

1 Comment

Great. I knew I needed push but I did this listedUsers = [name].push(i); :D How would I get the name I am trying to achieve in the second code? As well as later on alert each name. Say if the "log in" and thats what the var list is. I want User1 logged in User2 Logged In if you know what I'm saying

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.