Skip to content

Instantly share code, notes, and snippets.

@anthonycoffey
Last active June 1, 2019 19:46
Show Gist options
  • Save anthonycoffey/93e389d5211b1bec18a1bca50130ef00 to your computer and use it in GitHub Desktop.
Save anthonycoffey/93e389d5211b1bec18a1bca50130ef00 to your computer and use it in GitHub Desktop.
ES6 Computed Property Names in Object Literals
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