Iterating over two arrays at a time in Javascript

Posted by Ankur on Stack Overflow See other posts from Stack Overflow or by Ankur
Published on 2010-05-09T04:16:59Z Indexed on 2010/05/09 4:18 UTC
Read the original article Hit count: 225

I want to iterate over two arrays at the same time, as the values for any given index i in array A corresponds to the value in array B.

I am currently using this code, and getting 'undefined' when I call queryPredicates[i] or queryObjects[i], I know my array is populated as I print out the array prior to calling this, I haven't put all the other code in as it might be confusing, but if you think the problem is not evident from this I will edit the question:

function getObjectCount(){
    variables = queryPredicates.length; //the number of variables is found by the length of the arrays - they should both be of the same length
    queryString="count="+variables;
    for(var i=1; i<=variables;i++){
        alert(queryPredicates[i]);
        alert(queryObjects[i]); 
    }

Thanks

© Stack Overflow or respective owner

Related posts about javascript-arrays

Related posts about iteration