Join array in JavaScript _ basic knowledge-js tutorial

Source: Internet
Author: User
This article mainly introduces related information about the Association array in JavaScript. For more information, see The Code is as follows:


Var beatles = ["john", "Paul", "George", "Ringo"];

The beatles array above is a typical example of a traditional array: The subscript of each element is a number. Each time an element is added, the number is increased by 1 in turn. The subscript of the first element is 0, and that of the second element is 1. And so on.

If only the element value is given when the array is filled, the array will be a traditional array, and the subscript of each element will be automatically created and refreshed.

This default behavior can be changed by explicitly providing subscript for each new element when filling the array. You do not have to limit the number to an integer when giving a marker for a new element. You can also use a string:

The Code is as follows:


Var lennon = Array ();
Lennon ["name"] = "John ";
Lennon ["year"] = "1940 ";
Lennon ["living"] = false;

Such an array is called an associated array. Because strings can be used to replace numeric values, the code is more readable. However, this usage is not a good habit and is not recommended. Essentially, when creating an associated Array, you create the attributes of an Array object. In JavaScript, all variables are actually some type of objects. For example, a Boolean value is a Boolean object, and an Array is an Array object. In the above example, you actually added name to the lennon array, and year and living are the attributes. Ideally, you should not modify the attributes of an Array Object, but use a common Object ).

The above is all the content of this article. I hope you will like it.

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.