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

83
Views
Convert array of data into an object with properties

How do I convert an array into an object with properties: With the following data: ["Test Scenario ID", "Login-1"]

I would like to return an object with properties:

{1: "Test Scenario ID", 2: "Login-1"} // desired result

With the following, It maps the data into separate objects, but I would like it to be properties of a single object instead of an array of objects:

row.values.map( (e,i) => { return {i: e} })

[{1: "Test Scenario ID"}, {2: "Login-1"}] // the current result
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

One option is to use Object.fromEntries to turn an array of entries into the object.

const result = Object.fromEntries(
  row.values.map((e, i) => [i, e])
);

Another option is to take your array of multiple objects and put it through Object.assign to combine them.

const result = Object.assign(
  ...row.values.map( (e,i) => ({i: e}))
);
about 4 years ago · Juan Pablo Isaza Report

0

you can use this:

Object.assign({}, ['a','b','c']);    // {0:"a", 1:"b", 2:"c"}

The Object.assign() method copies all enumerable own properties from one or more source objects to a target object. It returns the modified target object.

you can read more about it here on MDN

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!