![]() |
ECMAScript 2019, also known as ES10, introduced features like Array.flat(), Array.flatMap(), Object.fromEntries(), and Symbol. description, and some string methods, for enhancing JavaScript’s capabilities and expressiveness. JavaScript 2019 (ES10) or ECMAScript 2019 new features are:
We will explore all the above methods along with their basic implementation with the help of examples. Method 1: String.trimStart() MethodThis method is used to trims leading whitespace characters from the beginning of a string, enhancing JavaScript’s string manipulation capabilities for improved data handling and formatting. Syntax: string.trimStart();
Example: Here the basic example of String.trimStart(). Javascript
Output
GeeksforGeeks Method 2: String.trimEnd() MethodThis method is used to removes trailing whitespace characters from the end of a string, offering enhanced string manipulation capabilities for improved data handling and formatting in JavaScript. Syntax: string.trimEnd()
Example: Here is the basic example String.trimEnd(). Javascript
Output
GeeksforGeeks Method 3: Object.fromEntries() MethodObject.fromEntries() converts an array of key-value pairs into an object, simplifying object creation from structured data in JavaScript. Syntax: Object.fromEntries( iterable );
Example: In this example we are using the above-explained method. Javascript
Output
{ name: 'Nikita', age: 21, city: 'Noida' } Method 4: Optional catch BindingOptional catch binding in ECMAScript 2019 allows omitting the catch parameter in try-catch blocks, simplifying error handling when the caught error object isn’t needed. Syntax: try {
// Code that may throw an error
} catch (error) {
// Code that may throw an error
}
Example: Here is the basic example of using try and catch method. Javascript
Output
Value of variable a is : 10 Method 5: Array.flat() MethodArray.flat() method collapses nested arrays within an array to a single-dimensional array, simplifying array manipulation and enhancing data processing in JavaScript. Syntax: arr.flat([depth])
Example: In this example we are using the above-explained method. Javascript
Output
[ '1', '2', '3', '4', '5', '6', '7' ] Method 6: Array.flatMap() MethodArray.flatMap() combines mapping and flattening of nested arrays within an array, simplifying data transformation and manipulation by applying a function and then flattening the result. Syntax: let A = array.flatMap(function callback(current_value, index, Array)) {
// It returns the new array's elements.
}
Example: In this example, the flatMap() method applies a function to each element of the num1 array, doubling and squaring each number, and then flattens the resulting arrays into a single-dimensional array. Javascript
Output
[ 2, 1, 4, 4, 6, 9, 8, 16 ] Method 7: Revised Array.Sort() MethodAfter ES2019, Array.sort() maintains relative positions of elements with equal values, ensuring stability in sorting algorithms for consistent results when sorting elements based on a value. Syntax: arr.sort(compareFunction)
Example: Javascript
Output
[ { name: 'Dinesh', score: 78 }, { name: 'Anil', score: 85 }, { name: 'Chinu', score: 85 }, { name: 'Balram', score: 90 } ] Method 8: Revised JSON.stringify() MethodBefore ES2019, JSON.stringify() broke UTF-8 code points (U+D800 to U+DFFF). Post-revision, it them, ensuring accurate conversion and compatibility with JSON.parse(). Syntax: let text = JSON.stringify("\u26D4");
Example: In this example we are using the above-explained method. Javascript
Output
Hello????Geeks Method 9: Separator Symbols Allowed in String LitteralsIn JavaScript ES2019, separator symbols (underscores) are allowed within numeric and string literals to improve readability without affecting their values or behavior. Syntax: let num1 = 1_000_000_000;
let str1 = 'Hello_World';
let text1 = "\u2028";
Example: In this example we are using the above mentioned methods. Javascript
Output
1000000000 Hello_World Method 10: Revised Function.toString() MethodFunction.toString() converts a function to a string representation, revealing its source code, including comments and formatting, facilitating debugging and dynamic code generation in JavaScript. Syntax: let result = myFunction.toString();
Example: Here the basic example of above mentioned method. Javascript
Output
function myFunction(name) { return `Hello, Geeks!`; } Supported browser:
|
Reffered: https://www.geeksforgeeks.org
JavaScript |
Related |
---|
![]() |
![]() |
![]() |
|
![]() |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 13 |