Array Definition method Array traversal method global variables and local variables definition assignment value and assignment address definition

Source: Internet
Author: User
Tags array definition

How to define arrays:

Method One: Use the new operator with the array () constructor to create

var arr = new Array ();

Method Two: Create an array of the specified length, with only one integer in ()

var arr = new Array (3);

  The length of the array: Arr.length, you can only count the length of a one-dimensional array.

Method Three: Add multiple array elements in parentheses (), separating each element with commas

var arr = new Array (10,20,30,40,50);

Mode four: use brackets [] to create an array

var arr = [10,20,30,40];

When you delete an array element with delete, only the content is purged, but the occupied space still exists.

Traversal of an array: for...in Loop statement

Grammar:

for (variable name in Object name)

{

Loop body Code;

}

The main loop (Traverse) all the properties of an object or all the elements in an array. It does not output the undefined element in an array.

Global variables and local variables:

Global variables: Variables defined outside the function, called global variables, can be used anywhere in a Web page, including within a function.

Local variables: Variables that can only be used within a function are called "local variables".

Note: The var keyword is omitted anywhere, and the variables defined are "global variables" (which can be used outside of the function) so, in general, do not omit the var keyword.

Assignment Value and assignment address:

Assignment value: Used to assign a basic data type (only one value) to a variable.

Reference address: Used to assign a composite data type (possibly with multiple values) to a variable. All two variables change at the same time.

Array Definition method Array traversal method global variables and local variables definition assignment value and assignment address definition

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.