-1

I tried to sample code for variable value assign in n object key using typescript. but it's not working can anyone give suggestion on value assign an object key.

Example Code

const data = "hai";
const objec = {
    data:{"dddd":"dfdfdf"}
}
console.log(objec)  

I need Output like this

{hai:{dddd:"dfdfdf"}}
Ivar
  • 6,138
  • 12
  • 49
  • 61
hari prasanth
  • 716
  • 1
  • 15
  • 35
  • Does this answer your question? [JavaScript set object key by variable](https://stackoverflow.com/questions/11508463/javascript-set-object-key-by-variable) – Ivar Nov 06 '19 at 12:35

1 Answers1

1

You can use []

const data = "hai";
const objec = {
    [data]:{"dddd":"dfdfdf"}
}
console.log(objec)  
Prashant Pimpale
  • 10,349
  • 9
  • 44
  • 84