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

200
Views
Cree JSON dinámicamente con claves y valores dinámicos en Express Js

Estoy obteniendo API en mi servidor Express que tiene varios pares de valores clave JSON en una matriz. Por ejemplo:

 [{ "quality": "best", "url": "https://someurlhere.example/?someparameters" }, { "quality": "medium", "url": "https://someurlhere1.example/?someparameters" }]

Y quiero crear una matriz de JSON de los datos recibidos en este formato:

 [{ "best": "https://someurlhere.example/?someparameters" }, { "medium": "https://someurlhere1.example/?someparameters" }]

He intentado hacer esto usando for loop

 for(let i=0; i < formats.length; i++){ arr.push({ `${formats[i].quality}` : `${formats[i].url}` }) }

Pero no funcionó para mí.

Por favor, ayúdame a lograr esto. Gracias de antemano :)

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Puede usar la función de map y crear un nuevo objeto a partir de ella.

Por ejemplo:

 let prevArr = [{ "quality": "best", "url": "https://someurlhere.example/?someparameters" }, { "quality": "medium", "url": "https://someurlhere1.example/?someparameters" }]; // Replace with your array let newArr = []; let obj = {}; prevArr.map(function(x) { obj = {}; obj[x["quality"]] = x.url; newArr.push(obj); });
over 4 years ago · Santiago Trujillo Report

0

const input = [{ "quality": "best", "url": "https://someurlhere.example/?someparameters" }, { "quality": "medium", "url": "https://someurlhere1.example/?someparameters" }]; const result = input.map((v, i) => { return { [v["quality"]]: v["url"] } }); console.log(result)
over 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!