ECMAScript 2024
JavaScript Version Numbers
Old ECMAScript versions was named by numbers: ES5 and ES6.
From 2016, versions are named by year: ES2016, 2018, 2020 ...
The 15th edition, ECMAScript 2024, is published in July 2024.
New Features in ES2024
- Object.groupBy()
- Map.groupBy()
- Temporal.PlainDate()
- Temporal.PlainTime()
- Temporal.PlainMonthDay()
- Temporal.PlainYearMonth()
Warning
These features are relatively new.
Older browsers may need an alternative code (Polyfill)
JavaScript Object.groupBy()
Example
// 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);
Try it Yourself »
Description
The Object.groupBy()
method groups elements of an object
according to string values returned from a callback function.
The Object.groupBy()
method does not change the original object.
Note:
The elements in the original and in the returned object are the same.
Changes will be reflected in both the original and in the returned object.
JavaScript Map.groupBy()
Example
// 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);
Try it Yourself »
Description
The Map.groupBy()
method groups elements of an object
according to string values returned from a callback function.
The Map.groupBy()
method does not change the original object.
Note:
The elements in the original and in the returned object are the same.
Changes will be reflected in both the original and in the returned object.
Object.groupBy() vs Map.groupBy()
The difference between Object.groupBy() and Map.groupBy() is:
Object.groupBy() groups elements into a JavaScript object.
Map.groupBy() groups elements into a Map object.