A JS object is basically an associative array containing a series of key-value pair. To create a JS object, use the new keyword. For example,
Var obj1 = new Object();
Obj1.member1 = “this is member 1”;
Obj1.member2 = 3
Another way to create members of an object is to use square bracket (array?) notation:
Obj1[“member1”] = “this is member 1”
The square bracket notation has an advantage that it can use character not allowed for variable name because the member name is specified as string. For example, Obj1[“1”] works as single digit 1 is not allowed in variable name. Obj1.1 will flag as error by JS.
Array can be generalized (viewed alternatively) as an object with numeric keys (0, 1, 2, ..).
No comments:
Post a Comment