I know that an array in JavaScript is nothing else than an object. When I define an array like that:
var array;
array = [ "a", "b", "c" ];
and run
Object.keys(array);
I get following array: ["0", "1", "2"]
. Array length of array
is 3
.
When I add a property like:
array["a"] = "d";
Object.keys()
is returning ["0", "1", "2", "a"]
, but array length of array
is still 3
.
But when I add a property like that:
array["3"] = "d";
the length of array
is now 4
.
If array
is just another object, how can I achieve that kind of behaviour when I start my object from scratch like var myArray = {}
?