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

305
Views
Uso del operador de propagación para actualizar el valor del diccionario, que es una matriz de objetos

Estoy tratando de guardar una carga útil de API en un diccionario. El modelo de datos de la API tiene los atributos "categoría", "id" y "nombre".

 let apiPayload = []; (async () => { let fetchValue = await fetch('https://asia-southeast1-citric-pager-319712.cloudfunctions.net/gcp-simple-api').then(response => { if (response.ok) { return response.json(); } throw response; }).then(data => { return data; }).catch(error => console.log(error)); console.log('fetchValue', fetchValue); let dictionary = Object.assign({}, ...fetchValue.map((x) => ({ [x.category]: [x] }))); console.log('dictionary', dictionary); })();

¿Cómo agrego un nuevo objeto de categoría en mi diccionario para que esté ordenado por categoría con objetos de categoría, por ejemplo?

 HTML: [{ category: "HTML", id: "blog-post", name: "Blog Post" }, {...}, {...}], JavaScript: [{ category: "JavaScript", id: "curry", name: "Curry"}, {...}, {...}]
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Aquí tienes:

 async function sample() { let categories = {} let fetchValue = [] //Array of object, plug your fetch data here fetchValue.forEach(e=>{ if(!categories[e.category]){ categories[e.category]= [e] }else{ categories[e.category].push(e) } }) }
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!