Skip to content

Javascript basic

Overview

With ECMAScript since 2015 you can use Spread Syntax ( …three dots):

let  people = { id: 4 ,firstName: 'John'};
people = { ...people, secondName: 'Fogerty'};
It's allow you to add sub objects:

people = { ...people, city: { state: 'California' }};
the result would be:

{
   "id": 4,
   "firstName": "John",
   "secondName": "Forget",
   "city": {
      "state": "California"
   }
}

Reference