DEV Community

loading...

Discussion on: ES6 dynamic key (name) for object & object property assignment

Collapse
dskaiser82 profile image
Daniel Kaiser

This one blew my mind. No loop needed!

const name = "com";
let i = 1;

const radioDevice = {
numberOfComs: 3,
[name + "" + i++]: "port 4556",
[name + "
" + i++]: "socket 12",
[name + "_" + i++]: "socket 15",
};