Home > Web Front-end > JS Tutorial > Prototype usage guide array.js_prototype

Prototype usage guide array.js_prototype

WBOY
Release: 2016-05-16 19:21:19
Original
1110 people have browsed it
$A = Array.from(iterable): Convert iterable into an array. If iterable defines the toArray method, call this method. Otherwise, use the length attribute of iterable to enumerate. If iterable does not The length attribute returns an empty array []

In addition to extending the methods of the Enumerable object, the Array object also extends the following methods,

Note that the following methods except clear do not change the original array, but returns a new array:

clear(): To clear the array, use arr.length=0

first(): Return the first element

last(): Return the last element

compact(): Remove null or undefined values ​​from the array Element

flatten(): Flatten the array, for example, [3,4,[6,7]] becomes [3,4,6,7]

without():
Remove the specified element, you can specify multiple values, such as [4,56,7,8].without(4,7) returns [56, 8]

indexOf(object): Returns the index of the specified element in the array, or -1 if it is not included

reverse(inline): Array built-in function reverse Enhanced, when inline is true, the effect is the same as the built-in reverse function, changing the value of the original array, otherwise the original value is not changed

reduce(): If the array has only one element, Then return this element, otherwise return the array itself

uniq(): Return an array without duplicate elements

clone(): Return a follow For arrays with the same array, the toArray method in Array overrides the toArray method in Enumerable and points to this method

inspect(): which is similar to the toString method of the array and returns the string of the object Represents, for example [2,3].inspect() returns "[2,3]"
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