Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.36 KB | None | 0 0
  1. const nestedArray = [['😉'],['😊'],['😇']]
  2. const nestedCopyWithSpread = [...nestedArray] // The spread operator makes a shallow copy
  3.  
  4. nestedArray[0][0] = '😡' // Whoops, a bug
  5.  
  6. console.log(...nestedArray) // 😡 😊 😇
  7. console.log(...nestedCopyWithSpread) // 😡 😊 😇
  8.  
  9. // A deep copy would require a library like lodash or Ramda's R.clone() method
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement