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

109
Views
Transforme una pestaña de valores clave en una matriz de valores clave

Me gustaría transformar una matriz de pestañas de valores clave en una matriz de valores clave

 rates.map(rate => { return { [rate]: account.vent.filter(v => v.rate === rate)[0] ?.vat, } }) (5) [{…}, {…}, {…}, {…}, {…}] 0: {10: 500} 1: {20: 630} 2: {5: undefined} 3: {19.6: undefined} 4: {1: undefined}

Tengo esto en mi consola, me gustaría algo más como:

 { 10: 500 20: 630 5: undefined 19.6: undefined 1: undefined }
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

Parece que reduce es un método más apropiado para su caso, ya que desea crear un objeto a partir de una matriz.

algo como

 rates.reduce((ratesObj, rate) => { ratesObj[rate] = account.vent.find(v => v.rate === rate)?.vat; return ratesObj; }, {})
about 4 years ago · Juan Pablo Isaza Report

0

Agrega esto y tus problemas se resolverán.

 .reduce(function(p,c){ return {...p,...c}; },{})

Su código se verá así después de agregar el código anterior

 rates.map(rate => { return { [rate]: account.vent.filter(v => v.rate === rate)[0] ?.vat, } }) .reduce(function(p,c){ return {...p,...c}; },{})
about 4 years ago · Juan Pablo Isaza Report

0

Prueba esto

 array.reduce((acc, item)=>{ return {...acc, ...item} },{})

Método de reducción: - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce

Un buen video sobre el método de reducción: - https://www.youtube.com/watch?v=IfieE2G3bfg

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!