-1
let fileName = "test.c";
let testCase = "Case1";
let test = {};
test.fileName = testCase;
console.log(test)

I need fileName property to be dynamic What is need is, like below

{
 "test.c":"Case1"
}

Can any one help me

Nijesh W
  • 39
  • 1
  • 6

2 Answers2

1
test.fileName = testCase;

Won't work in this case. Should be

test[fileName] = testCase;
Suresh Atta
  • 118,038
  • 37
  • 189
  • 297
1

You can use the ES6 computed property syntax:

{
    [fileName]: "Case1"
}

This will be interpreted dynamically as:

{
    "test.c": "Case1"
}
trincot
  • 263,463
  • 30
  • 215
  • 251