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

129
Views
How i can to convert array to object of array in react?

I have a data in array

["Avengers","Batman","Spiderman","IronMan"]

how I can to covert to below

{"Avenger":"Avenger","Batmane":"Batman","Spiderman":"Spiderman","Ironman":"Ironman"}
about 4 years ago · Santiago Gelvez
3 answers
Answer question

0

You can do it like this:

let arr = ["Avengers","Batman","Spiderman","IronMan"];
let obj = arr.reduce((acc, item)=> ({...acc, [item]: item}) , {});
console.log(obj);

about 4 years ago · Santiago Gelvez Report

0

Someone else mentioned reduce, but I recommend against, copying objects at every iteration.

Here's a more performant approach.

const arr = ["Avengers","Batman","Spiderman","IronMan"];
const obj = {};

for (const el of arr) {
  obj[el] = el;
}

console.log(obj);

about 4 years ago · Santiago Gelvez Report

0

You can use reduce to convert array to object. You can see some examples in here Convert Array to Object

about 4 years ago · Santiago Gelvez 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!