Home > Web Front-end > JS Tutorial > Summary of Array object method attributes in javacsript

Summary of Array object method attributes in javacsript

迷茫
Release: 2017-03-26 17:23:06
Original
1653 people have browsed it

There are three main properties: constructor; length; prototype;

Constructor (English meaning: constructor): Returns a reference to the array function that created this object. For example: var arr=new Array(); arr.constructor=Array;

length (English meaning: length): Set or return the number of elements in the array. Note: The length is always 1 greater than the last subscript of the array; set the length of the array: if the array is longer than the set length, the array will be truncated. If the array length is shorter than the set length, undefined will be added later;

Prototype (English meaning: prototype): enables you to add properties and methods to objects (prototype chain, inheritance of properties);

There are 12 commonly used methods:

 concat(arrayX); used to join two or more arrays; (arrayX is required, the array to be linked) (the original array is not changed, but another new array is created);

join( [separator]); is used to put all elements in the array into a string. (Separator English meaning: separator);

pop(); delete and return the last element of the array; (If the array is already empty, pop() does not change the array and returns an undefined value.); (First in, last out);

push();Adds one or more elements to the end of the array and returns the new length. (First in, last out);

Reverse(); Used to reverse the order of elements in an array; (Change the original array without creating a new array.);

shift() ;Remove the first element from the array and return the value of the first element. (Change the original array without creating a new array.);

 slice(start,[end]);Returns the selected elements from the existing array. (start is a negative number, then it specifies the position starting from the end of the array. That is, -1 refers to the last element, -2 refers to the second-to-last element, and so on.) ((start,end)== =[start,end] includes the front and not the end);

Sort([function]); Sort the elements of the array. (according to the ascii code table); such as: (arrange according to the size of the numbers: function sortNum(a,b){return a-b});

splice(index,number,[item]);index: Position; number: quantity; item: item to be replaced;

toString(); Convert the array to a string and return the result (same effect as push without parameters);

unshift ();Adds one or more elements to the beginning of the array and returns the new length;

 valueOf();Returns the original value of the Array object.

The above is the detailed content of Summary of Array object method attributes in javacsript. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template