Object Literal is like map in Java or associative array in PHP. In other word, it's a JSON format, but less losely in syntax.
>> var names = {"luna":"maya","lady":"gaga","aura":"kasih"};
or
>> var names = {};
>> names["luna"] = "maya";
>> names.lady = "gaga";
After initialization like above, you can access it through:
>> alert(names["lady"]);
or
>> alert(names.lady);
You can use either number or string as key.
No comments:
Post a Comment