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

94
Views
JS Uso de nombres clave dinámicos de objetos

Necesito usar un objeto que contenga mi configuración, principalmente la asignación de nombres clave. Pero no puedo entender por qué no funciona

 //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: []} } }

Todo parece bastante simple pero me da error! Entonces, ¿qué estoy haciendo mal?

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

0

Prueba esto:

 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

El problema es que estás agregando una cadena, no un valor variable.

 //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!