user3033194 user3033194 - 2 months ago 4x
Javascript Question

Is JavaScript array index a string or an integer?

I had a generic question about JavaScript arrays. Are array indices in JavaScript internally handled as strings? I read somewhere that because arrays are objects in JavaScript, the index is actually a string. I am a bit confused about this, and would be glad for any explanation.


That is correct so:

> var a = ['a','b','c']
> a
[ 'a', 'b', 'c' ]
> a[0]
> a['0']
> a['4'] = 'e'
> a[3] = 'd'
> a
[ 'a', 'b', 'c', 'd', 'e' ]