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
What is the problem with my code? array.push doesn't seem to work. Thank!
Change
conversations.push = (jQuery(this).attr("data-conversationid"));
For
conversations.push( jQuery(this).attr("data-conversationid") );
Array.push() - a function call, not an assignment.
Array.push()
array.pushis a function. Use it as:
array.push
conversations.push(jQuery(this).attr("data-conversationid"));