Reputation: 65
I create a Object like below,
var s = {
`1234`:`string`
}
But, It will throw the below Error,
Uncaught SyntaxError: Unexpected template string
How Can I create Such Elements?
Upvotes: 5
Views: 4854
Reputation: 386654
You could use computed property names with brackets, because the template literal returns a string, which works like a variable.
var object = { [`1234`]:`string` };
console.log(object);
Upvotes: 9
Reputation: 6825
You should be using quotes instead of backticks, try this:
var s = { '123': 'string'}
Upvotes: 1