Menu
×
   ❮     
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS DSA TYPESCRIPT ANGULAR ANGULARJS GIT POSTGRESQL MONGODB ASP AI R GO KOTLIN SASS VUE GEN AI SCIPY CYBERSECURITY DATA SCIENCE INTRO TO PROGRAMMING BASH RUST

Basic JavaScript

JS Tutorial JS Syntax JS Variables JS Operators JS If Conditions JS Loops JS Strings JS Numbers JS Functions JS Objects JS Dates JS Arrays JS Sets JS Maps JS Math JS RegExp JS Data Types JS Errors JS Debugging JS Events JS Programming JS References JS UTF-8 Characters JS Versions

JS Advanced

JS Functions JS Objects JS Classes JS Iterations JS Promises JS Modules JS HTML DOM JS Windows JS Web API JS AJAX JS JSON JS jQuery JS Graphics JS Examples JS Reference


ECMAScript 2024


New Features in JavaScript 2024

FeatureDescription
Object
groupBy()
Groups object elements according to values returned from a callback function
Map
groupBy()
Groups map elements according to values returned from a callback function
String
isWellFormed()
Returns true if a string is well formed
String
toWellFormed()
Returns a new string where "lone surrogates" are replaced with Unicode U+FFFD
Promise
withResolvers()
Atomics
waitAsync

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 return a new object.

The Object.groupBy() method does not change the original object.

Note:

The elements in the original and in the returned object are the same.

Future changes will be reflected in both the original and in the returned object.


JavaScript Map.groupBy()

Example

// Create a Map
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 a map according to string values returned from a callback function.

The Map.groupBy() method returns a new map.

The Map.groupBy() method does not change the original object.

Note:

The elements in the original and in the returned object are the same.

Future 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.



JavaScript String isWellFormed()

The isWellFormed() method returns true if a string is well formed.

Otherwise it returns false.

A string is not well formed if it contains lone surrogates.

Examples

let text = "Hello world!";
let result = text.isWellFormed();
Try it Yourself »
let text = "Hello World \uD800";
let result = text.isWellFormed();
Try it Yourself »

Lone Surrogates

A lone surrogate is a Unicode surrogate code point that is not part of a valid surrogate pair used to represent characters in UTF-16 encoding.


JavaScript String toWellFormed()

The String method toWellFormed() returns a new string where all "lone surrogates" are replaced with the Unicode replacement character (U+FFFD).

Examples

let text = "Hello World \uD800";
let result = text.toWellFormed();
Try it Yourself »

×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
sales@w3schools.com

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
help@w3schools.com

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.

Copyright 1999-2025 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.