Dynamic Property Names in Objects in Javascript


Use square brackets to set object properties with dynamic names.

Source Code

let propertyName = 'name';
let person = { [propertyName]: 'John' };
console.log(person.name);
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments