My Tech Notes
Search This Blog
Javascript: create a object property from a variable
Option 1:
const name = 'n'; let obj = {}; obj[name]=1;
Option 2(ES6):
const name = 'n'; let obj = { [name] : 1}
No comments:
Post a Comment
Newer Post
Older Post
Home
View mobile version
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment