The method _______ is used to sort the elements of an array.

  • sort()
  • splice()
  • split()
  • reduce()
The correct method is sort(). JavaScript arrays have a built-in sort() method that is used to sort the elements of an array in ascending order by default. You can also provide a compare function to customize the sorting behavior. For example, myArray.sort((a, b) => a - b) sorts the array numerically.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *