I understand that when index names are used to push values in Javascript, they essentially work like objects. But what I don't understand is the following behaviour -
person = [];
person[0] = "Someone";
person["test"] = "SomeoneElse"
Inputting person
on the console prints ["Someone"]
and I could see no information about person.test
.
person.test
does print SomeoneElse
. However, if I go console.log(person)
, I get ["Someone", test: "SomeoneElse"]
.
Curious to check if this makes sense, I tried to create a structure like this one -
var experiment = ["Someone1", test1: "SomeoneElse1"]
and what I get is
Uncaught SyntaxError: Unexpected token
What am I missing?
Thanks in advance!