Guest User

Untitled

a guest
Nov 21st, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. var myObject = {
  2. name: 'myObject',
  3. number: 9001,
  4. nestedObject: {
  5. nestedName: 'nestedName',
  6. nestedBasicArray: [1,2,3],
  7. nestedObjectArray: [{firstThing: 11, secondThing: 12}, {firstThing: 21, secondThing: 22}, {firstThing: 31, secondThing: 32}]
  8. }
  9. }
  10.  
  11. var {
  12. name,
  13. number,
  14. nestedObject: {
  15. nestedName,
  16. nestedBasicArray: [a, b, c],
  17. nestedObjectArray: [...d]
  18. }
  19. } = myObject
  20.  
  21. // These values have the same key name in our object, so we declare and call them directly
  22. console.log(`Name is ${name}`)
  23. console.log(`Name is ${number}`)
  24. console.log(`Nested Name is ${nestedName}`)
  25.  
  26. // Here we use some basic pattern matching
  27. console.log(`a is ${a}`)
  28. console.log(`b is ${b}`)
  29. console.log(`c is ${c}`)
  30.  
  31. // We use the object spread '...' operator to deconstruct this array of objects
  32. console.log('d is:')
  33. console.log(d);
  34.  
  35. // Let's use an example function to dig a little deeper
  36. d.map(({firstThing, secondThing}) => {
  37. console.log(`firstThing is ${firstThing}`);
  38. console.log(`secondThing is ${secondThing}`);
  39. })
Add Comment
Please, Sign In to add comment