First, the object
Speaking of objects, we do not naturally think of the object-oriented self-encapsulation of a class, the same JS also follow this code, in the Web programming almost every day in the use of JSON. Yes, this is an object, but the fields below this object are string and value types, such as.
var delivery = { 1, "2014-11-25", "PJS"};
From the above you can see that delivery only have basic strings and numeric types, of course, you can play more than that, in addition to the basic type, we can also define an array type, function Type field, as follows.
var delivery = { 1, "2014-11-25", // three available shipping addresses address: ["Beijing", "Shanghai", "Nanjing"], "PJS", // support distribution according to Logic function () { //Logic code .... return true ; } };
Now the object is created, and the next step is how to use it? There are usually two ways of doing this:
<1> "." Operator
This way, I think people should know, so there is nothing to say, such as: Delivery.way.
<2> Index method
Second, array
The array is defined in two ways, literal and array constructors, such as:
var s = [1, "Ctrip"]; var New Array (1, "Ctrip");
We will find a phenomenon, the array incredibly can and objects to pull a piece, the end will make you dazzled, perhaps this is the flexibility of non-type, pros and cons.
We can see that by s.name= the "cnblogs" of such objects, you can add key and value to the array, and you can also pass S.name and
s["name"] Output result value, this means that the array is essentially a class, but in the class to do some high-level package, such as the need for timing statistics length size, also caused by
To output a result value in two ways, but this results in the coexistence of an indexed array and an associative array.
Reference: http://www.cnblogs.com/huangxincheng/p/4116778.html
JavaScript Learning Essays-objects and arrays