js--The property method of an Array object __js

Source: Internet
Author: User
Tags array length
Creating and manipulating arrays
1 of the three methods created by the array:
The Var arr=new array ();//creates an empty array without specifying a length.
var arr=new arry (4);//Create an array with a length of 4
var arr=new arry (1,2,3, "a", "B");//Create an array and initialize it.
The array is actually dynamic and can be extended freely.
2 Custom array constructors and create arrays
You need to first define an array and implement the creation and initialization of the array within the constructor. ‘
This pointer is required.
3 function Myarry (N,INDEX2)
{
for (Var i=0;i<n;i++)
{
This[i]=index2;
}
This.length=n;
}
n is an array length, INDEX2 is the initial parameter.
var arr=new myarry ("Jiahzne");
for (var i =0;i<10;i++)
{
document.write (Arr[i]);
}

4 properties of the Arry object
Length: Returns the array lengths.
Prototype:arry.prototype.methodname=functionname/function;
5 Methods of Arry objects:
Concat (Arry): Links other arrays to the end of the current array.
Join (separator): Links An array element to a string. Separator is a link separator.
Pop (): Deletes the last element of the array.
Push (""): Adds an element to the array.
Reverse (): reverse-order the array emissions.
Shift (): Deletes the first element of an array.
Slice (start,end): Gets part of a vegetarian group.
Sort (): Sorts the array.
Splice (Start,count,datacount): (Replace the starting item, the number of replacements, the array to replace)
Unshift ("", ",..): Inserts new data at the beginning of the array.
ToString (): Returns a string containing all the elements in the array, linked by commas.
62-D arrays need to be defined by themselves, using custom array constructors to create object methods.

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.