JavaScript .allSettled()

garanews's avatar
Published Jul 27, 2021Updated Oct 8, 2022
Contribute to Docs

The .allSettled() method returns a new Promise object that resolves to an array after all Promises in iterableObject have been resolved or rejected. This is ideal when working with multiple Promises that are independent of one another’s completion. Each element in the resolved array will be the result of the Promises in iterableObject.

  • A full-stack engineer can get a project done from start to finish, back-end to front-end.
    • Includes 51 Courses
    • With Professional Certification
    • Beginner Friendly.
      150 hours
  • Learn how to use JavaScript — a powerful and flexible programming language for adding website interactivity.
    • Beginner Friendly.
      15 hours

Syntax

Promise.allSettled(iterableObject);

The iterableObject is usually an array of Promise objects. If the array is empty, a Promise object that resolves into an empty array will be returned.

Example

With an empty array:

Promise.allSettled([]).then((values) => {
console.log(values); // Output: []
});

Codebyte Example

With an array of Promises:

Code
Output
Loading...

All contributors

Contribute to Docs

Learn JavaScript on Codecademy

  • A full-stack engineer can get a project done from start to finish, back-end to front-end.
    • Includes 51 Courses
    • With Professional Certification
    • Beginner Friendly.
      150 hours
  • Learn how to use JavaScript — a powerful and flexible programming language for adding website interactivity.
    • Beginner Friendly.
      15 hours