What's new in ES2021
What’s new in ES2021
Let’s get started with the first of the new ES2021 features:
String.prototype.replaceAll
String.replace is a useful method that allows us to replace a pattern in a string with something else. The problem is that if we want to use a string as a pattern and not a RegEx, only the first occurrence will get replaced.
As the name implies, String.replaceAll will do exactly what we need in this scenario, replace all the matching pattern, allowing us to easily replace all mentions of a substring, without the use of RegEx:
Promise.any
During the past years we’ve seen new methods such as Promise.all and Promise.race with ES6, Promise.allSettled last year with ES2020 and ES2021 will introduce a new one: Promise.any.
I bet you can already tell what it does from the name of the method.
Promise.any shorts-circuits once a given promise is fulfilled ...