Spread Operator
The Spread operator allows an iterable to expand in places where 0+ arguments are expected. It is mostly used in the variable array where there is more than 1 value is expected.
Syntax:
let variablename1 = [...value];
Example: In this example, we are using spread operator to create arr2 with elements from arr1 and add 4, 5 and create obj2 by merging obj1 properties and adding c: 3, d: 4.
Javascript
// Spread operator with arrays let arr1 = [1, 2, 3]; let arr2 = [...arr1, 4, 5]; console.log(arr2); // Spread operator with objects let obj1 = { a: 1, b: 2 }; let obj2 = { ...obj1, c: 3, d: 4 }; console.log(obj2); |
Output
[ 1, 2, 3, 4, 5 ] { a: 1, b: 2, c: 3, d: 4 }
JS 2015 or ECMAScript 6 (ES6)
JS 2015 (ES6) also known as ECMAScript 6 (ES6), ECMAScript 6 (ES6) is a significant update to JavaScript, introducing arrow functions, classes, template literals, let and const for variable declaration, enhanced object literals, destructuring, and more modern features for better code organization and readability.
Contact Us