var my = {};
my["1"] = "tom";
my["2"] = "tony";
document.writeln(my["2"]);
A simple question, what is the {} called? I know [] is called arraylist and I can do my.indexOf() etc. on it, but this doesn’t work with {}.
Where can I find a list of operation I can perform with list with {}
Specifically, the
{}in that case denotes object literal notation. It’s a syntactical feature of the language that is one way of creating anObject.This…
…simply creates an Object that doesn’t own any properties directly.
You can use the same object literal syntax to give the Object properties immediately.
An equivalent code for creating an empty object would be to use the
Objectconstructor…You should be aware that an Object in JavaScript is unordered. The numeric indices you gave it will not guarantee any sort of ordering when enumerating the object. To get an ordered loop, you’d need to get an Array of the keys, sort them, then iterate the Array.
For example…