Javascript Array
Javascript Array.
Contents |
Constructor
Static Methods
Methods
- push(element)
Adds new items to the end of an array.
Parameters:
element - The element to be added at the end of the array.
Return:
The new length.
Note: this method will change the original array.
Ex:
var test_arr = [1,2];
var res = testarr.push(3);
// test_arr -> 1,2,3
// res -> 3
- pop()
Removes the last element of an array.
Return:
The removed element.
Note: this method will change the original array.
- concat(array1)
- concat(array1,array2,...)
Join two or more arrays.
Note: This method does not change the existing arrays, but returns a new array, containing the values of the joined arrays.
Ex: array1 = [1,2] array2 = [2,3,4] array3 = [4,5] var res = array1.concat(array2, array3); //res -> [1,2,2,3,4,4,5]
- join()
- join(separator)
The elements will be separated by a specified separator. The default separator is comma (,).
Note: This method will not change the original array.
- reverse()
Reverses the order of the elements in an array.
Note: this method will change the original array.
- shift()
- unshift()
- slice()
- splice()
// Changes the content of an array, adding new elements while removing old elements. // Returns an array containing the removed elements // array.splice(index , howMany[, element1[, ...[, elementN]]]) // array.splice(index ,[ howMany[, element1[, ...[, elementN]]]])
- sort()
- includes()
- indexOf()
- lastIndexOf()
Properties
- length
Returns the number of elements in an array.