JavaScript Array Object array tutorial (1/4)

Source: Internet
Author: User

Let's take a look at its definition:

The code is as follows:

var arrayobj = new Array ()
var arrayobj = new Array ([size])
var arrayobj = new Array ([element0[, element1[, [, ELEMENTN]]])

Where: Arrayobj is the variable name assigned to the array object.
Size because the subscript of an array is zero-based, the subscript of the created element will be from zero to size-1.
Element0,..., ELEMENTN This creates an array of n + 1 with an element of n + 1. You must have more than one element when you use this syntax.
If you pass only one parameter to the array's constructor, and the argument is a number, it must be an unsigned 32-bit integer (approximately 4 billion). The value becomes the size of the array. A run-time error occurs if the value is numeric, but is less than 0 or is not an integer.

If a single value is passed to the array constructor and is not a number, the Length property is set to 1, and the unique element value becomes a single passed-in parameter.

Because the JS array is an analytic array, that is, although you can assign multiple elements to an array, only the elements that contain the data exist. This reduces the amount of memory used by the array.

The array object has three built-in properties: Constructor,length,prototype I will write a special article on constructor, Prototype,arguments and other object properties, here is not to say more. Here we look at some of the methods built into the array, which is important to us because it is often used.

Concat method: Joins two or more arrays and returns a new array. It is worth noting that (reference type) for object parameters copied from the array being connected to the new array. Copying still points to the same object, regardless of which of the new array and source array changes, will cause another change; (value type) copy only its value for a numeric value or string that is attached to the new array. A change in the value of an array does not affect the value in the other array. Example:

Home 1 2 3 4 last page

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.