![]() |
The toSorted() method is introduced in JavaScript with the ECMAScript 2023 (ES2023) specification. It provides a safe way to sort an array of elements in ascending order. It will return the new array and the existing array will not be affected. Sorts elements by converting them to strings by default. Undefined values are positioned at the end of the sorted array. Syntax://With no parameters Example 1: To demonstrate sorting the array using the toSorted() method in JavaScript without passing any parameter.
Output: Existing Array: [60, 78, 90, 34, 67] Example 2: Ascending Order – Passing the “
Output: Existing Array: [60, 78, 90, 34, 67] Example 3: To demonstrate sorting the array in ascending order using the toSorted() method in JavaScript.
Output: Existing Array: [60, 78, 90, 34, 67] |
Reffered: https://www.geeksforgeeks.org
JavaScript |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 13 |