0

I want to ask about the NodeJS object(JSON), let see the case.

const myname = Date.now();
const scheme = {
  custom_name: value, //the case
};

from the example above, what I want is the custom_name using the value of myname, is that possible?

ade ramdani
  • 333
  • 1
  • 3
  • 12

1 Answers1

1

Sure it is, just use square bracket notation.

Of course, with date the toString representation will be used for the key:

const myname = Date.now();
const value = "foo"
const scheme = {
  [myname]: value, //the case
};
console.log(scheme)
Jamiec
  • 133,658
  • 13
  • 134
  • 193