Array Method Array.prototype

Source: Internet
Author: User

Object.prototype

The value of an array is an ordered set, each value is called an element, and each element has a numeric position number in the array, which is the index, and the array in JS is a weak type, and the array can contain different types of elements. Array elements can even be objects or other arrays

Length range: 1====2 23 Party-1

New Array (//UNDIFIND*100)

arr[5]=10;

Arr.length//6

Push ()

Unshift ()

Shift ()

Pop ()

var arr=[1,true,undifind,{x:1},[1,2,3]];

Array.prototype

Array.prototype.join () By default, you can customize-------convert an array to a string

Demo

Create a fixed character loop string of a certain length

New Array (2). Join ("AB");//abab

The new Array (100) creates an array of length 100, and each element is Undifind,join ignored Undifind

array.prototype.reverse======= the array in reverse order, it changes the original array

Array.prototype.sort () ======== The array is sorted (by default, sorted by string, you can customize the Sort method) the original arrays are modified

Array.prototype.concat () array merge original array not modified

Array.prototype.slice () ===== returns a partial array left closed right open interval support negative-1 means the last element-2 means the second-lowest element of the original array does not change

Array.prototype.splice () ====== array concatenation modifies the original array to accept two parameters The second parameter indicates the length of the deleted element returns the deleted element

The Array.prototype.forEach () array traversal parameter is a function of three parameters 1 is the corresponding element 2 is subscript 3 is the iterated array itself does not modify the original array

Array.prototype.map () array mapping does not modify the original array

Array.prototype.filter () array filtering returns an array that conforms to the requirements and does not modify the original array

Array.prototype.every () returns true to False array to determine that all elements are in accordance with

Array.prototype.some () returns true to False if the array determines that some elements conform

Array.prototype.reduce () The difference between aggregating an array into a result and reduceright is that the default is from the array from left to right reduceright is the array from right to left

Array.prototype.reduceRight ()

Demo

Gets the maximum value of the array

var arr=[30,40,3,20,10,9,8];

var max=arr.reduce (function (x, y) {

Return x>y?x:y;

});

You can specify the initialization value

var max=arr.reduce (function (x, y) {

Return x>y?x:y;

},20);

Returns an array of ARR with 20 maximum values

Array.prototype.indexOf () array retrieval can specify where to start retrieving the first parameter: the element that needs to be instrumented. Second parameter: Where to start retrieving

Array.isarray () IsArray is a function on the array constructor, not a method on the prototype prototype, and cannot be called directly using an array

Array.isarray ([]);

Array Method Array.prototype

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.