javascript - how are negative array indexes interpreted -
this question has answer here:
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
Post a Comment