javascript - how are negative array indexes interpreted -


i create array (in chrome's console)

a = [1, 2, 3]; // [1, 2, 3] 

then assign

a[-1] = 123; // 123 

this not throw error, resulting array not changed:

a // [1, 2, 3] 

but can read -1 property successfully:

a[-1] // 123 

how indexing work javascript arrays? why not show new value have added? apparently treats property. why?

as arrays objects, because can assign arbitrary properties array including negative numbers fractions.

negative indexes don't act real indexes.

but not have impact on length of array.


Comments

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -