Skip to main content

Command Palette

Search for a command to run...

What is the array method in JavaScript?

Published
•3 min read•View as Markdown
What is the array method in JavaScript?

what is an array in javascript ??

In simple words, an array is an object that can store multiple values at once

the syntax for array declaration

const arrayName = [ elements];

ex : const country = ['India' , 'Australia ' , 'New Zealand ' , ' Germany];

In javascript, there are different types of methods available to manipulate an array some of them are

1. concat()

This method simply join/merge the two array and gives a new array example as shown in below screenshot

concat.png

2. reverse()

As the name of the method, it was used to reverse the array

reverse.png

3. push()

push() method is used to insert/add a new element in the array and gives the length of the new array

push.png

4. pop()

the pop() method is used to remove the last element from the array and it will modify the existing array

pop.png

5. unshift()

unshift() adds one or more elements to the beginning of an array and returns the new length of the array.

unshift.png

6. shift()

shift() method is used to remove the element situated on starting or [0] index of an array

shift.png

7. slice()

slice() is used to cut the array from a specific index and gives a new array and it doesn't modified the original array

slice.png

8. fill( )

This method fills the elements in an array with a static value and returns the modified array.

fill.png

9. splice()

The splice() method changes the contents of an array by removing or replacing existing elements and/or adding new elements in place and it doesn't modify the original array it will give a new array with the removed value

splice.png

10. indexOf( )

indexOf() returns the position of a specified value in an array.

indexof.png

11. includes()

The includes() method checks if an array contains a specified element or not and if the element is present in the array then it will return true else false

includes.png

12. length()

The length gives the length of the array.

length.png

13. join()

The join() method is used to join the elements of an array into a string. The elements of the string will be separated by a specified separator and its default value is a comma(, ).

join.png

14. sort()

The sort() method allows you to sort elements of an array in place. Besides returning the sorted array, the sort() method changes the positions of the elements in the original array.

By default, the sort() method sorts the array elements in ascending order with the smallest value first and the largest value last.

sort.png

15. toString()

this method is used to convert the array element into string format

tostring.png