Table of contents
Array :-
Array in any programming language, is used to store list of elements or collection of multiple items which can be accessed by a single variable. In this blog we will learn and discuss about the applications of array methods.
Methods to add or remove elements :-
push( ) --> add an items to the end of the array.
pop ( ) --> remove an item from the end of the array.
shift ( ) --> remove an item from beginning of the array.
unshift ( ) --> Used to add an item to the beginning of the array.
concat ( ) --> It joins two different arrays and returns a new array.
slice (start, end ) --> It removes the elements from given array from index start to end and returns a new array containing removed elements.
splice (index, deleteCount, ...items) --> It removes the elements starting from index till deleteCount and adds ...items.
Note :- In methods like slice and splice starting point is inclusive and end point is exclusive.
for example :-
Some more methods :-
- fill (value, start, end) --> changes elements in the array to static value from the start index to end index and returns the modified array.
- filter ( ) --> It creates the shallow copy of the portion of the given array, filtered down to just the elements from the given array that pass the test implemented by the provided function.
- copyWithhin( ) --> It copies part of an array to other location of the same array.
- every ( ) --> This method tests whether all elements in the array pass the test implemented by the provided function. It returns a Boolean value.
- forEach( ) --> It executes a provided function once for each array element.
- indexOf ( ) --> It returns the first index at which the given element can be found in the array. If the element is not present then it will return -1.
- join ( ) --> This method concatenates all the elements of the given array and returns the modified array.
- map ( ) --> This method creates the new Array and the elements of this new array is a result of the function applied to every element of the given array.
- sort( ) --> sorts the elements of an array and returns the reference to the same array.
- toString( ) --> returns a string representing the specified array and its elements.
We have discussed some important methods of array. There are more to discuss.