Skip to content

Instantly share code, notes, and snippets.

@RianFuro
Created October 12, 2018 09:18
Show Gist options
  • Save RianFuro/fe75d6cc88974f8165bfe51f7793bdc9 to your computer and use it in GitHub Desktop.
Save RianFuro/fe75d6cc88974f8165bfe51f7793bdc9 to your computer and use it in GitHub Desktop.
One important difference between Object.assign and the object spread operator for arrays in javascript
const arr = [1, 2, 3]
console.log({...arr, newKey: "I'm new!"}) // { '0': 1, '1': 2, '2': 3, newKey: "I'm new!" }
console.log(Object.assign(arr, {newKey: "I'm new!"})) // [ 1, 2, 3, newKey: "I'm new!" ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment