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 15th edition, ECMAScript 2024, is set to be published in July 2024.
// Create an Array const fruits = [ {name:“apples”, quantity:300}, {name:“bananas”, quantity:500}, {name:“oranges”, quantity:200}, {name:“kiwi”, quantity:150} ]; // Callback function to Group Elements function myCallback({ quantity }) { return quantity > 200 ? “ok” : “low”; } // Group by Quantity const result = Object.groupBy(fruits, myCallback); |
The Object.groupBy() method groups the elements of an object based on string values returned by a callback function.
This method does not modify the original object.
Note: The elements in both the original and returned objects are the same. Any changes made will be reflected in both the original and the returned object. |
// Create an Array const fruits = [ {name:“apples”, quantity:300}, {name:“bananas”, quantity:500}, {name:“oranges”, quantity:200}, {name:“kiwi”, quantity:150} ]; // Callback function to Group Elements function myCallback({ quantity }) { return quantity > 200 ? “ok” : “low”; } // Group by Quantity const result = Map.groupBy(fruits, myCallback); |
The Map.groupBy() method groups the elements of a Map based on string values returned by a callback function.
This method does not modify the original Map object.
Note: The elements in both the original and returned objects are identical. Any changes made will be reflected in both the original and the returned object. |