Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width">
- <title>JS Bin</title>
- </head>
- <body>
- <script id="jsbin-javascript">
- // Destructuring w/ Arrays and Objects
- //extract array elements or object properties and store them in variables
- 'use strict';
- var a = 1;
- var b = 2;
- console.log('a: ' + a + ' and b: ' + b);
- var numbers = [2, 5, 7];
- num1 = numbers[0];
- num3 = numbers[2];
- console.log(num1 + ', ' + num3);
- //Object destructuring, property name defines which property we take
- var _name$age = { name: 'bob', age: '93' };
- var name = _name$age.name;
- var age = _name$age.age;
- console.log('name: ' + name + ' and age: ' + age);
- //Array destructuring, order defines which property we take
- </script>
- <script id="jsbin-source-javascript" type="text/javascript">// Destructuring w/ Arrays and Objects
- //extract array elements or object properties and store them in variables
- //Array destructuring, order defines which property we take
- const [a,b] = [1,2];
- console.log(`a: ${a} and b: ${b}`);
- const numbers = [2,5,7];
- [num1, ,num3] = numbers;
- console.log(`${num1}, ${num3}`);
- //Object destructuring, property name defines which property we take
- const {name, age} = {name: 'bob', age: '93'}
- console.log(`name: ${name} and age: ${age}`);</script></body>
- </html>
Add Comment
Please, Sign In to add comment