1. replaceAll
- syntax
"<string>".replaceAll(<pattern>);
- Phương thức này trả về một chuỗi string mới đã được thay thế theo pattern.
- Example:123456const p = 'The quick brown fox jumps over the lazy dog. If the dog reacted, was it really lazy?';console.log(p.replaceAll('dog', 'monkey'));// Output: "The quick brown fox jumps over the lazy monkey. If the monkey reacted, was it really lazy?"
<pattern>
là một string hoặc cũng có thể là một regex12345678const p = 'The quick brown fox jumps over the lazy dog. If the dog reacted, was it really lazy?';const regex = /Dog/ig;console.log(p.replaceAll(regex, 'ferret'));// expected output: "The quick brown fox jumps over the lazy ferret. If the ferret reacted, was it really lazy?"
2. Promise.any
Promise
any nhận vào 1 mảngPromise Object
, và nó sẽreslove
sau khi có 1Promise Object
trong mảngresolve
- Example:12345678910const promise1 = Promise.reject(0);const promise2 = new Promise((resolve) => setTimeout(resolve, 100, 'quick'));const promise3 = new Promise((resolve) => setTimeout(resolve, 500, 'slow'));const promises = [promise1, promise2, promise3];Promise.any(promises).then((value) => console.log(value));// Output: "quick"
3. Logical Assignment Operator
- Logical Assignment Operator sẽ combine(cho phép kết hợp) giữa toán tử logic và biểu thức gán.
- Example:123456789101112a ||= b// equals toa = a || (a = b)a &&= b// equals toa = a && (a = b)a ??= b// equals toa = a ?? (a = b)
4. Underscores as Numeric Separator
- Example:12345const billion = 1_000_000_000;console.log(billion); // 10000000001_000_000_000 === 1000000000; // true