3
var conversations = new Array();
jQuery('.CChatWindow').each(function(){
    if (jQuery(this).is(":visible") && jQuery(this).attr("data-conversationid") != 0) {
        alert(jQuery(this).attr("data-conversationid")); // returns 1 and 2
        conversations.push = (jQuery(this).attr("data-conversationid"));
    }
});
alert(conversations); // returns an empty string

Whats the problem with my code? array.push does not seem to work. Thanks!

1
  • 1
    why are you trying to overwrite conversations.push ?! Commented May 22, 2012 at 11:20

2 Answers 2

7

Change

conversations.push = (jQuery(this).attr("data-conversationid"));

To

conversations.push( jQuery(this).attr("data-conversationid") );

Array.push() is a function call and not an assignment.

Sign up to request clarification or add additional context in comments.

1 Comment

@Chris: Then you should click the checkmark next to this answer
3

array.push is a function. Use it like:

conversations.push(jQuery(this).attr("data-conversationid"));

Comments

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.