0

I have a constant and I want to use it as a key of another object. However, it does not work. What is the best solution for this?

export const URL_QUERY_PARAMS = Object.freeze({
    parentId: "parentId",
    groupId: "groupId"
})

const queryParam = {  {URL_QUERY_PARAMS.groupId : "test1",
     "nodePath" : "test2"}
emplo yee
  • 205
  • 2
  • 13

1 Answers1

1

Use array format to make dynamic key

 const queryParam = { "nodePath" : "test2" };
 queryParam[URL_QUERY_PARAMS.groupId] = "test1";
Niklesh Raut
  • 34,013
  • 16
  • 75
  • 109