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

4
  • 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. Commented Oct 25, 2017 at 12:04
  • Ah, i got it, its not pushing, i am just assigning keys to my array Commented Oct 25, 2017 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 []. Commented Oct 25, 2017 at 12:07
  • You can get an array ok keys by doing Object.keys(arr["alpha"]) which you can iterate Commented Oct 25, 2017 at 12:23

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.