JavaScript – Destructuring

Github Code

This post (like the others) will be short as I am going to show two ways to destructure objects in JavaScript.  ‘Destructuring’ in JavaScript is the method of ‘extracting data from arrays, objects, maps and sets’ (reference #1). More simply stated, it is a way of getting a specific element (or elements) from a larger object by into either a small object and/or by itself.

To run it:

  • Download the code

screen-shot-2017-02-27-at-8-37-10-pm

  • Run the project

screen-shot-2017-02-27-at-8-19-56-pm

  • Review output

screen-shot-2017-02-27-at-8-18-29-pm

screen-shot-2017-02-27-at-8-17-23-pm

  • Example one is a simple object which extracts two properties from a larger object

Screen Shot 2017-02-27 at 8.19.12 PM.png

  • Example two is a much more complex object

screen-shot-2017-02-27-at-8-22-54-pm

screen-shot-2017-02-27-at-8-23-11-pm

Stay tuned!

References

  1. http://wesbos.com/destructuring-objects/
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s