Last active
June 1, 2019 19:46
-
-
Save anthonycoffey/93e389d5211b1bec18a1bca50130ef00 to your computer and use it in GitHub Desktop.
ES6 Computed Property Names in Object Literals
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
var keys = { | |
name: 'name', | |
email: 'email', | |
password: 'password' | |
} | |
var obj = { | |
[`_${keys.name}`]: 'John Doe', | |
[`_${keys.email}`]: '[email protected]', | |
[`_${keys.password}`]: 'password123' | |
} | |
console.log(obj) | |
/* | |
{ | |
_email: "[email protected]", | |
_name: "John Doe", | |
_password: "password123" | |
} | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment