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. 回答1: That is correct so: > var a = ['a','b','c'] undefined > a [ 'a', 'b', 'c' ] > a[0] 'a' > a['0'] 'a' > a['4'] = 'e' 'e' > a[3] = 'd' 'd' > a [ 'a', 'b', 'c', 'd', 'e' ] 回答2: Formally, all property names are