I have an array with both integer and string index.
For some reason, it seems that $.each does not correctly iterate over the string indexes.
The below output is:
idx: 0
1
2
3
idx: 1
4
5
6
idx: 2
7
8
9
// actual
idx: 3
a
b
c
// expected
idx: abc
10
11
12
Here is the code I tested with:
<html>
<head>
<title>jQuery - each</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
var a = new Array();
a.push(0);
a[0] = [1, 2, 3];
a.push(1);
a[1] = [4, 5, 6];
a.push(2);
a[2] = [7, 8, 9];
a.push("abc");
a["abc"] = [10, 11, 12];
$.each(a, function (idx, v) {
alert("idx: " + idx);
alert(v[0]);
alert(v[1]);
alert(v[2]);
});
});
</script>
</head>
<body>
</body>
Thank you very much for your help,
Richard Hughes
change your code like so:
this will return
Note that when you use a string as index, your data structure is an object (and not an array)