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

178
Views
Create dynamic key in object JS

So I want to create a dynamic key in a js object. I know I can create it like this but id doesn't fullfil my requirements

return {
  [dynamicKey]: value
}

But the problem is I want something like this

return {
  [dynamicKey]_id: value
}

but it doesn't let me, I tried concatenating but it didn't work.

return {
  [dynamicKey] + '_id': value
}

I've also searched online for a solution but couldn't find any.

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

0

you need to put your _id string inside of the square brackets or as part of the dinamicKey var.

return {
  [dinamicKey + '_id']: value
}
dinamicKey += '_id';
return {
  [dinamicKey]: value
}
about 4 years ago · Juan Pablo Isaza Report

0

Any expression in the square braces will be executed just like a normal expression. So how about this:

return {
    [dinamicKey + '_id']: value
}
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!