Guest User

Untitled

a guest
Jan 18th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width">
  6. <title>JS Bin</title>
  7. </head>
  8. <body>
  9.  
  10. <script id="jsbin-javascript">
  11. // Destructuring w/ Arrays and Objects
  12. //extract array elements or object properties and store them in variables
  13. 'use strict';
  14.  
  15. var a = 1;
  16. var b = 2;
  17.  
  18. console.log('a: ' + a + ' and b: ' + b);
  19. var numbers = [2, 5, 7];
  20. num1 = numbers[0];
  21. num3 = numbers[2];
  22.  
  23. console.log(num1 + ', ' + num3);
  24.  
  25. //Object destructuring, property name defines which property we take
  26. var _name$age = { name: 'bob', age: '93' };
  27. var name = _name$age.name;
  28. var age = _name$age.age;
  29.  
  30. console.log('name: ' + name + ' and age: ' + age);
  31. //Array destructuring, order defines which property we take
  32. </script>
  33.  
  34.  
  35.  
  36. <script id="jsbin-source-javascript" type="text/javascript">// Destructuring w/ Arrays and Objects
  37. //extract array elements or object properties and store them in variables
  38. //Array destructuring, order defines which property we take
  39. const [a,b] = [1,2];
  40. console.log(`a: ${a} and b: ${b}`);
  41. const numbers = [2,5,7];
  42. [num1, ,num3] = numbers;
  43. console.log(`${num1}, ${num3}`);
  44.  
  45. //Object destructuring, property name defines which property we take
  46. const {name, age} = {name: 'bob', age: '93'}
  47. console.log(`name: ${name} and age: ${age}`);</script></body>
  48. </html>
Add Comment
Please, Sign In to add comment