JS base (Array Method)

An object method for an array

concat()

Usage: to connect two or more arrays, and returns the result.

Parameters: may be a single or a plurality of elements, may be one or more arrays may be mixed and used.

Returns: Returns an array of post-splicing.

Features: Does not change the original array.

Precautions: Su parameters passed though an array, but the operation is an array of elements inside.

join()

Usage: put all the elements of the array into a string. Elements separated by the specified delimiter.

Parameters: specified symbol for each element in the array is connected, the default is a comma.

Return Value: string splicing.

Features: Does not change the original array.

Precautions: toString () function and join the same time does not pass parameters, separated by commas default.

pop()

Usage: Removes and returns the last element of the array.

Parameters: No parameters, as specified delete the last.

Return Value: The return value to delete that element.

Features: change the original array.

push()

Usage: add one or more elements to the end of the array, and returns the new length.

Parameters: You can be one, multiple, add elements to the array represents the inside, the first parameter is required.

Return Value: to add a new value of the specified array length of the array.

Features: directly change the original array.

reverse()

Usage: reverse the order of elements in the array.

Parameters: No parameters.

Return Value: returns an array of the elements in reverse order.

Features: change the original array.

shift()

Usage: Remove the first item in the array.

Parameters: No parameters, because the first designated deletion.

Return Value: The return value to delete that element.

Features: change the original array.

unshift()

Usage: add one or more elements to the beginning of an array and returns the new length.

Parameters: may be one, may be a plurality, showing the beginning of the add elements to the array, the first parameter required.

Return Value: to add a new value of the specified array length of the array. 

Features: change the original array.

slice()

Usage: Returns selected elements from an existing array.

Parameters: two parameters, where the first predetermined start (0 is the first), from the back, if the start is negative (-1 is the last, and so on). The second parameter determines where to stop, counting with a parameter. The first parameter required, the second parameter can be omitted, omit the second argument began to intercept correspondence from the end of the array.

Return Value: returns the value of those elements taken.

Features: Does not change the original array.

sort()

Usage: The element of the array is sorted.

参数:可选。规定排序顺序。必须是函数。

返回值:排序后的数组。

特点:改变原数组。

splice()

用法:删除元素,并向数组添加新元素。(增加、删除、修改数组任意位置元素)。

参数:多个参数,第一个参数规定了从哪个索引开始操作(可为负值,从-1开始代表最后一个),第二个参数规定了从第一个参数对应的索引删除几个元素(为零则不删除),第三个及以后的参数规定了添加的元素。前两个参数必须,第三及以后的参数可选。

返回值:删除的元素的值。

特点:改变原数组。

indexOf()

用法:返回某个指定的字符串值在字符串中首次出现的位置。

参数:两个参数,第一个参数规定了需检索的字符串值。第二个参数规定在字符串中开始检索的位置(合法值为对应数组下标的范围内的值)。第一个参数必需,第二个参数可选。

返回值:某个指定的字符串值在字符串中首次出现的位置(若没有出现则返回-1)。

特点:不改变原数组。

Guess you like

Origin www.cnblogs.com/MDZZZ/p/12167111.html