Use routines for arrays and objects in JavaScript

Source: Internet
Author: User

JavaScript arrays

The following code creates an array named cars:

1 //Way One:2 varCars =NewArray ();3 4Cars[0] = "Volvo";5CARS[1] = "BMW";6CARS[2] = "QQ";7 8 //Way Two:9 varCars =NewArray ("Volvo", "BMW", "QQ");Ten  One //Way Three: A varCars =Newarray["Volvo", "BMW", "QQ";
JavaScript Objects

Objects are separated by curly braces. Inside the parentheses, the properties of the object are defined in the form of name and value pairs (name:value). Attributes are separated by commas:

1 // Create object 2 var person = {id= "666666", firstname= "bills", Lastname= "Gates"};

The object (person) in the example above has three attributes: FirstName, LastName, and ID. Spaces and lines do not matter. Declarations can span multiple lines:

1  // Creating Objects 2 var person = {3     id= "666666",4     firstname= "Bills",  5     lastname= "Gates"6

Object properties are addressed in two ways:

1 name=person.lastname; 2 name=person["LastName"];

Use routines for arrays and objects in JavaScript

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.