12/11/18

Distructuring cheatsheet

Since I keep find myself forgot the ES6 destructuring syntax again and again I decided to publish this cheatsheet:

If you want to print one property of object:


const object = {name:'vasia'};
const {name} = object; 
console.log(`${name}`); // vasia 


If you want to this property to be named differently (bio)


const object = {name:'vasia'};
const {name: bio} = object; 

console.log(`${bio}`); // vasia 


If this property is inside other property (person)


const object ={person: {name:'vasia'}};
const {person:{name}} = object;

console.log(`${name}`); // vasia 
Hope this post will make me remember...

No comments:

Post a Comment

Getting started with docker

It is very simple to get started usig docker. All you need to do-is download the docker desktop for your system Once you get docker syste...