The Web Dev Guide by Wishtack
  • The Web Dev Guide by Wishtack
  • HTML
    • HTML Tags
    • HTML Attributes
    • Content Formatting
    • Empty Tags vs Content Tags
    • Some Links
  • ECMAScript
    • Some History
    • Language Properties
    • Single-Threaded thus Asynchronous
    • The Event Loop
    • Classes
    • Hoisting is Dead: var vs. let vs. const
    • this & "binding"
    • Arrow Functions
    • Template Strings
    • Syntactic Sugar
      • Spread
      • Destructuring
      • Rest
      • Object Literal Property Value Shorthand
    • Named Parameters
    • Compatibility
  • Tools
    • Node.js
    • NPM
    • Yarn
    • Webpack
    • WebStorm
    • StackBlitz
  • DOM
    • What Is It?
    • Element Selection
    • Element Modification
    • Events
  • Forms
    • The <form> tag
    • Form elements
    • Form validation
  • Networking
    • Fetch Web API
  • CSS
    • Selectors
    • Transforms
    • Transitions
    • Animations
    • Web Animations API
    • Sass
  • Responsive Web Design
    • Viewport
    • Media Queries
    • Grid Layout
    • Flex Layout
    • Frameworks & Libraries
  • Web APIs
  • Testing
    • Unit Testing
    • End to End Testing
  • Security
    • Injection
    • DOM XSS
    • Insecure Direct Object Reference
    • Cross-Site Request Forgery
    • Client vs API Validation
    • API Unauthorized Access and Data Leak
  • More Links
Powered by GitBook
On this page
  • Array Spread
  • Object Spread
  1. ECMAScript
  2. Syntactic Sugar

Spread

Array Spread

const itemList = [1, 2, 3];
const additionalItemList = [5, 6];
​
const newItemList = [...itemList, 4, ...additionalItemList];
​
console.log(newItemList); // [1, 2, 3, 4, 5, 6]

Object Spread

Handy for merging objects or for respecting immutability.

const user = {
    firstName: 'Foo',
    lastName: 'BAR',
    email: 'invalid@wishtack.com'
};
​
const newUser = {
    ...user,
    email: 'foo.bar@wishtack.com',
    phoneNumber: '+6 12 34 56 78'
};
​
console.log(newUser);
// {
//    firstName: 'Foo',
//    lastName: 'BAR',
//    email: 'foo.bar@wishtack.com',
//    phoneNumber: '+6 12 34 56 78'
//}
PreviousSyntactic SugarNextDestructuring

Last updated 6 years ago