Created
October 12, 2018 09:18
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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