JavaScript array explanation (how to declare and calculate arrays)

Source: Internet
Author: User
Tags array to string print object

1. array declaration method

(1): arrayObj = new Array (); // create an Array

Var arr1 = new Array ();

(2): arrayObj = new Array ([size]) Create an Array and specify the length. Note that the length is not the upper limit.

Var a = new Array (5 );

(3): arrayObj = new Array ([element0 [, element1 [,... [, elementN]) Create an Array and assign values

Var a = new Array (["B", 2, "a", 4,]);

(4): arrayObj = [element0, element1,..., elementN]

Var a = ["B", 2, "a", 4,];

(Note): note the difference between "[]" and "[]".

Var a = new Array (5); // creates an Array of 5 characters.

Var a = new Array ([5]); // creates an Array with a length of 1 and a first value of 5.

2. Array Operation (Transfer address)

Var t2 = new Array (); t2 [0] = 1; t2 [1] = 2; test2 (t2); // transfer address (Array) function test2 (var2) {for (var I = 0; I <var2.length; I ++) {var2 [I] = var2 [I] + 1 ;}} for (var I = 0; I <t2.length; I ++) {alert (t2 [I]);}
Articles you may be interested in
  • Js array to string, js string to array method summary
  • Rational use of MySQL database indexes to make the database run efficiently
  • JavaScript array operation function Summary (push, pop, join, shift, unshift, slice, splice, concat)
  • PHP generates continuous numbers (letters) Array Function range () analysis, PHP lottery program function
  • Php converts a multi-dimensional array to a one-dimensional array
  • Js print array, js Print Object Method
  • Php uses array_flip to implement array key-value exchange to remove array duplicate values
  • Javascript restricts that only numbers (including decimal places) can be entered in the text box)

Related Article

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.