ES6 Nested Object Example

extracting variables from a nested object with new variable names

JS

const LOCAL_FORECAST = {
  yesterday: { low: 61, high: 75 },
  today: { low: 64, high: 77 },
  tomorrow: { low: 68, high: 80 }
};

// es5 access to nested object variables with variable name change
// const lowToday = LOCAL_FORECAST.today.low;
// const highToday = LOCAL_FORECAST.today.high;

// es6 access to nested object variables with variable name change
const { today: { low: lowToday, high: highToday } } = LOCAL_FORECAST;

console.log(lowToday); // should be 64
console.log(highToday); // should be 77
..

External Link for ES6 Nested Object Example

Other Items in javascript
Page Views

This page has been viewed 427 times.

Search Code
Search Code by entering your search text above.
Welcome

This is my test area for webdev. I keep a collection of code snippits here, mostly for my reference. Also if i find a good site, i usually add it here.

❤👩‍💻🕹

Random Quote
Interesting...

Me