I have four DIV elements on my page. Each has it’s own array which I attached using data().
Depending on user interaction (on page navigation) jquery stores loaded element IDs in one of the arrays.
The setup and pushing elements works and looks like this:
$('div:jqmData(role="panel")').each(function(index) {
if ( $(this).jqmData('hash') == 'history' ) {
var id = $(this).jqmData('id');
$(this).data("stack", []);
// inital entry = startpage
$(this).data("stack").push('#'+$(this).find('.starter').attr('id'));
}
});
Adding elements:
$('div:jqmData(role="page")').bind( "pagechange", function( event) {
var $targetPanel = $( event.target ),
$targetPage = '#'+ $.mobile.path.stripHash( hash );
$targetPanel.data("stack").push($targetPage);
});
I now need to know which array is the longest and what the last entry was?
No clue how to do that…
Can’t use maxValue or math, as I only have entries like #pageSome, #pageOther. There must be a better way than looping through all arrays, getting their length and trying to if-else highest value…
Thanks for help!
You can use the sort method to find the longest array
Then in order to get those arrays to be sorted, you could get them with a function like so:
or if the data in the arrays don’t change often, you could push in the arrays as they are built in the two functions specified in the question.
EDIT per the latest information via comments
Then when you want to reference the longest array and use it as a jQuery selector, you can use the following code: