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!
asked May 22, 2012 at 11:18
Chris
4,38410 gold badges47 silver badges87 bronze badges
2 Answers 2
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.
answered May 22, 2012 at 11:19
qwertymk
35.6k31 gold badges127 silver badges184 bronze badges
Sign up to request clarification or add additional context in comments.
1 Comment
qwertymk
@Chris: Then you should click the checkmark next to this answer
array.push is a function. Use it like:
conversations.push(jQuery(this).attr("data-conversationid"));
answered May 22, 2012 at 11:20
Niclas Sahlin
1,1279 silver badges15 bronze badges
Comments
lang-js
conversations.push?!