Code:
- var ar = new Array();
- ar['nice'] = "hello";
- alert(ar.length);
- //keeps on giving zero
This is because associative arrays are treated like objects and hence they do not have the "length" attribute. To traverse through the array, you can use this:
Code:
- var ar_ct = 0;
- var ar = new Array();
- ar['nice'] = "hello";
- for (i in ar)
- {
- alert(ar[i]); // value is "hello"
- }
No comments:
Post a Comment