JavaScript Learning Essays-objects and arrays

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.