0

Here is my jsfiddle

Here is my array looks like

var arr = [];
arr['alpha'] = {'a':'1','b':'1'};
arr['beta'] = {'a':'2','b':'4'};
console.log(arr)

When i take console.log(arr.length) It says 0. So i can't able to for loop this one

How can i iterate this array ?

Note :

I don't want to use jquery, i prefer only javascript

SA__
  • 1,782
  • 3
  • 20
  • 41
  • 1
    You can't have named keys for your array. (Technically, you can, but what you're really doing is assigning properties to your array, which is my JS is telling you the array has no length). Instead, consider using an `object` for this purporse. – Nick Oct 25 '17 at 12:04
  • Ah, i got it, its not pushing, i am just assigning keys to my array – SA__ Oct 25 '17 at 12:06
  • @SA__ You need to either use an integer index for your array, or switch to using an object.. ex: `var obj = {};` instead of `[]`. – caesay Oct 25 '17 at 12:07
  • You can get an array ok keys by doing `Object.keys(arr["alpha"])` which you can iterate – kevinSpaceyIsKeyserSöze Oct 25 '17 at 12:23

0 Answers0