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.
Loading...
Related Quiz
- Which of the following is NOT an argument passed to an event listener when it is invoked?
- What is the most common issue developers might face when working with closures and loops together?
- What is the purpose of the this keyword inside a constructor function?
- Which method would you use to add a new property to an object after it has been created?
- You are reviewing a junior developer's code and see the following line var x = 10;. You want to advise them to use a declaration that maintains block scope, which keyword should they use instead of var?