JavaScript sort() Method

This method sorts the elements of an array in alphabetical order in ascending order.

Example: In this example, we will sort the array alphabetically using the sort() method.

Javascript
let array = ["Hello", "w3wiki", "JavaScript"];
console.log(array);
array.sort();
console.log(array);

Output
[ 'Hello', 'w3wiki', 'JavaScript' ]
[ 'w3wiki', 'Hello', 'JavaScript' ]

What are the Important Array Methods of JavaScript ?

In this article, we will try to understand various important Array methods (like push(), pop(), and so on) with the help of certain examples.

Let us first understand how we can create an array in JavaScript by using certain syntax provided.

Syntax:

let array = [element1, element2, .....]

Alternatively, we may also use the Array class (using a new keyword along with the Array class default constructor) for creating new Array elements, but it is always recommended that we must prefer using the above literal syntax.

let array = new Array (element1, elemnet2, .....);

Example: In this example, we will create an array using both the methods discussed above.

Javascript
let array = ['Hello',
    'w3wiki', 'JavaScript'];
console.log(array);

let newArray = new Array('Hello',
    'w3wiki', 'JavaScript');
console.log(newArray);

Output:

['Hello', 'w3wiki', 'JavaScript']
['Hello', 'w3wiki', 'JavaScript']

Now that we have understood the creation of an array with the help of an example, let us now jump into several methods which are associated with the array.

JavaScript Array Methods:

Table of Content

  • JavaScript push() Method
  • JavaScript pop() Method
  • JavaScript shift() Method
  • JavaScript unshift() Method
  • JavaScript indexOf() Method
  • JavaScript includes() Method
  • JavaScript concat() Method
  • JavaScript forEach() Method
  • JavaScript sort() Method
  • JavaScript map() method
  • JavaScript reduce() Method
  • JavaScript filter() Method
  • JavaScript find() & findIndex() Method
  • JavaScript slice() & splice() Method
  • JavaScript some() and every() Method
  • Javascript forEach() method
  • JavaScript Array reverse() Method
  • Javascript Array every() method

Similar Reads

JavaScript push() Method

This method is used to insert the elements from the end into an array....

JavaScript pop() Method

This method deletes the last element present in the array....

JavaScript shift() Method

This method is used to delete the first element from the array....

JavaScript unshift() Method

This method is used to add the elements in the array from the front side....

JavaScript indexOf() Method

This method is used to find the index of a particular element in an array....

JavaScript includes() Method

This method is used to check whether the array contains the specified element or not....

JavaScript concat() Method

This method is used to concat or basically join two different arrays from end to end....

JavaScript forEach() Method

This method works as a loop over an array where for every element the function just runs once only. This method is useful for the purpose of reducing the syntax of the for-loop, but this method doesn’t return anything in its output....

JavaScript sort() Method

This method sorts the elements of an array in alphabetical order in ascending order....

JavaScript map() method

This method iterates over an array, transforms the array according to user-specified conditions and returns a new array. Using this shorter syntax, one could easily make code more readable and understandable....

JavaScript reduce() Method

This method uses a reducer function that reduces the results into a single output....

JavaScript filter() Method

This method is used to filter out the contents, as per the user-specified condition, in the form of a new array....

JavaScript find() & findIndex() Method

This method finds out the first value which passes the user-specified conditions and findIndex() method finds out the first index value which passes the user-specified conditions....

JavaScript slice() & splice() Method

slice() selects the specified number of elements without affecting the original array elements whereas splice() removes the selected elements from the original array itself....

JavaScript some() and every() Method

The some() method checks the user-specified conditions on some elements of an array (i.e. it checks for a few elements only), whereas every() method checks the user-specified conditions on every element of an array then returns the results in true or false....

Javascript forEach() method

The forEach() method in JavaScript is used to execute a provided function once for each element in an array....

JavaScript Array reverse() Method

The reverse() method is used to reverse the order of the elements in an array. This method modifies the original array and returns the reversed array....

Javascript Array every() method

The every() method is used to check if all elements in the array pass the test implemented by the provided function. It returns a boolean value true if all elements satisfy the test otherwise returns false....