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

230
Views
How to create object fields dynamically based on values in Javascript?

I have an object array like this:

const values = [{name: 'name1', index: 1}, {name: 'name2', index: 2}, {name: 'name3', index: 3}]

Is it possible to create such an object dynamically?

const result = {
  name1: 1,
  name2: 2,
  name3: 3
}
almost 4 years ago · Santiago Trujillo
1 answers
Answer question

0

what you can do is the following!

const values = [{name: 'name1', index: 1}, {name: 'name2', index: 2}, {name: 'name3', index: 3}];
const result = {};
values.forEach(value => result[value.name] = value.index);

console.log(result); // {name1: 1, name2: 2, name3: 3}
almost 4 years ago · Santiago Trujillo 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!