Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

91
Views
JS Using objects dinamic keynames

I need to use object which contains my settings, mainly keynames assignment. But I cant figure out why it does not work

//This is my object which contains names of the keys of another object
let setup={
  param1:'data1',
  param2: 'data2'
}

//So here is the main object where I need to use values as a keynames
const StatDataObj = {
  DataFields: {
    ['setup.param1']: {Blocks: [],Patch: []},
    ['setup.param1']: {Blocks: [],Patch: []}
  }
}

Everything seems quite simple but it gives me error! So what im doing wrong?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Try this:

const setup = { param1:'data1', param2: 'data2' };

const StatDataObj = {
  DataFields: {
    [setup.param1]: { Blocks: [], Patch: [] },
    [setup.param2]: { Blocks: [], Patch: [] }
  }
};

console.log(StatDataObj);

about 4 years ago · Juan Pablo Isaza Report

0

The problem is that you adding string, not variable value

//This is my object which contains names of the keys of another object
let setup={
  param1:'data1',
  param2: 'data2'
}

//So here is the main object where I need to use values as a keynames
const StatDataObj = {
  DataFields: {
    [setup.param1]: {Blocks: [],Patch: []},
    [setup.param1]: {Blocks: [],Patch: []}
  }
}

console.log(StatDataObj)

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!