Additional ECMAScript Features
You can also use the following ECMAScript features when writing SuiteScript 2.1 code:
-
Array.prototype.flat([depth=1])
-
Recursively flattens nested arrays into a single array, up to a given depth
-
Can be used to filter out empty arrays
-
-
Array.prototype.flat([depth]) …
Flattens nested arrays returned from sub-tasks
-
Array.prototype.flatMap(callbackFn[, thisArg])
-
Equivalent to first calling map(callbackFn) on an array then flattening (one level deep)
-
Superior performance
-
-
Object.fromEntries(iterable)
-
Constructs an object from an iterable of key-value pairs
-
A reverse operation to Object.entries(obj)
-
Whereas Object.entries does not emit key-value pairs for Symbol keys, Object.fromEntries fully supports Symbols
-
-
Promise.any(promises) - fulfilled
-
Takes an iterable of Promises
-
Returns a Promise that is fulfilled as soon as the first promise in the iterable is fulfilled, with the value of that first fulfilled promise
-
-
Promise.any(promises) and AggregateError - rejected
-
When all Promises in the iterable reject, the returned Promise is also rejected
-
AggregateError is a new Error sub-type; it has a property called errors that holds an array of inner errors
-
The inner errors may or may not be Error instances
-
-
Promise.allSettled(promises)
-
Returns a Promise that resolves when all input promises are settled
-
Resolved value is an array of result objects corresponding to the input promises
-
By comparison, Promise.all rejects based on the first observed rejection among the input promises
-
-
Nullish coalescing operator
-
Returns a right-hand side operand if the left-hand side operand is null or undefined (nullish); otherwise returns left-hand side
-
Short-circuits
-
Makes your code shorter and easier to read
-
Proper replacement for the bug-prone use of || (logical OR operator)
-
-
Optional chaining
-
Similar to '.' operator except that it short-circuits to undefined if the left-hand side is nullish, protecting you from null reference errors
-
Makes your code shorter and easier to read
-
-
Logical assignment operators - &&=, ||=, ??=
-
Combine condition and assignment into a single operation
-
Short-circuits
a ( a = b ) becomes a = b
-
-
Miscellaneous
-
String.prototype.trimStart
-
String.prototype.trimEnd
-
BigInt
-
String.prototype.matchAll
-
String.prototype.replaceAll
-
WeakRef
-
Underscore separators in numerical literals
-