Javascript does not create two separate arrays -- it simply creates an object where you can reference it's properties via an associative array syntax. Try the following out in your console:
var test = [];
test[0] = "value0";
test["col1"] = "value1";
test["col2"] = "value2";
console.log(test.length);
If you run the above code, you will see that the length of the array is actually just 1. The values for keys "col1" and "col2" are added as properties to the array object, not as entries in the array. Assuming that all the entries that you added to your javascript array were strings (eg., all the php generated keys were strings), then you can easily loop through all the keys in order using this:
for (key in test) {
console.log( test[key] );
}
The above code in our example would print out:
value0
value1
value2
Hope this clears up what is happening to your javascript array/object.
Update: If you need/want the 0..n elements to match your properties you could execute this after creating your initial javascript object with the associative references:
var test = [];
test["col1"] = "value1";
test["col2"] = "value2";
var i = 0;
for (key in test) {
test[i] = test[key];
i++;
}
In our example above, you would actually end up with 4 keys. Running this code:
for (key in test) {
console.log( "[" + key + "] --> " + test[key] );
}
outputs:
[0] --> value1
[1] --> value2
[col1] --> value1
[col2] --> value2
However, you could also just pull the two associative values using the index count like this:
for (var j = 0; j < test.length; j++) {
console.log( "[" + j + "] --> " + test[j] );
}
This would print just the 2 values like this:
[0] --> value1
[1] --> value2
Again, hope this helps!