Earlier ECMAScript versions were named by numbers, such as ES5 and ES6. Since 2016, versions have been named by year, like ES2016, ES2018, and ES2020. The 14th edition, ECMAScript 2023, was released in June 2023.
ES2023 introduced the findLast() method, which begins searching from the end of an array and returns the value of the first element that meets a given condition.
const temp = [27, 28, 30, 40, 42, 35, 30]; let high = temp.findLast(x => x > 40); |
The findLastIndex() method returns the index of the last element in an array that meets a specified condition.
const temp = [27, 28, 30, 40, 42, 35, 30]; let pos = temp.findLastIndex(x => x > 40); |
ES2023 introduced the toReversed() method for arrays, providing a safe way to reverse an array without modifying the original.
Unlike the reverse() method, which alters the original array, toReversed() creates a new array with the reversed elements, leaving the original array unchanged.
const months = [“Jan”, “Feb”, “Mar”, “Apr”]; const reversed = months.toReversed(); |
ES2023 introduced the toSorted() method for arrays, offering a safe way to sort an array without modifying the original.
Unlike the sort() method, which changes the original array, toSorted() creates a new sorted array, leaving the original array unchanged.
const months = [“Jan”, “Feb”, “Mar”, “Apr”]; const sorted = months.toSorted(); |
ES2023 introduced the toSpliced() method for arrays, providing a safe way to splice an array without modifying the original.
In contrast to the splice() method, which alters the original array, toSpliced() creates a new array with the changes, leaving the original array unchanged.
const months = [“Jan”, “Feb”, “Mar”, “Apr”]; const spliced = months.toSpliced(0, 1); |