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

128
Views
Transforme una matriz de objetos en pares de valores clave con uno de los valores como clave

Tengo una serie de objetos como este:

 const arr = [ { question_Number: 205, question_Text: "Enter Engine Number", }, { question_Number: 497, question_Text: "Whether imported?", }, { question_Number: 547, question_Text: "Whether goods are new?", }, { question_Number: 206, question_Text: "Select Vehicle Condition", },

];

y quiero transformarlo en un objeto de pares clave/valor como este:

 const result = { 205: { type: "string", title: "Enter Engine Number", }, 497: { type: "string", title: "Whether imported?", }, 547: { type: "string", title: "Whether imported goods are new?", }, 206: { type: "string", title: "Select Vehicle Condition", },

};

¿Cómo puedo lograr este resultado usando javascript simple o incluso lodash?

Gracias.

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

0

Podría mapear entradas con nuevos objetos.

 const data = [{ question_Number: 205, question_Text: "Enter Engine Number" }, { question_Number: 497, question_Text: "Whether imported?" }, { question_Number: 547, question_Text: "Whether goods are new?" }, { question_Number: 206, question_Text: "Select Vehicle Condition" }], result = Object.fromEntries(data.map(({ question_Number, question_Text: title }) => [question_Number, { type: 'string', title }])); console.log(result);
 .as-console-wrapper { max-height: 100% !important; top: 0; }

about 4 years ago · Juan Pablo Isaza Report

0

Puede hacer esto con cosas integradas, pero creo que esto sería más comprensible para ver qué está pasando, algo muy rápido:

 const input = [ { question_Number: 205, question_Text: "Enter Engine Number", }, { question_Number: 497, question_Text: "Whether imported?", }, { question_Number: 547, question_Text: "Whether goods are new?", }, { question_Number: 206, question_Text: "Select Vehicle Condition", } ] const transformArray = (arr) => { let result = {} for (let i = 0; i < arr.length; i++) { result[arr[i].question_Number] = { type: typeof arr[i].question_Text, title: arr[i].question_Text } } return result } console.log(transformArray(input))

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!