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

579
Views
Cómo iterar una matriz de objetos

Necesito revisar una matriz de objetos y devolver una matriz que contenga el "número de impuestos" ordenado por los nombres. ¿Cómo podría hacerlo?

 const paddockManagers = [ { id: 1, taxNumber: '132254524', name: 'JUAN TAPIA BURGOS' } , { id: 2, taxNumber: '143618668', name: 'EFRAIN SOTO VERA' } , { id: 3, taxNumber: '78903228', name: 'CARLOS PEREZ GONZALEZ' } , { id: 4, taxNumber: '176812737', name: 'ANDRES VIÑALES CIENFUEGOS' } , { id: 5, taxNumber: '216352696', name: 'OSCAR PEREZ ZUÑIGA' } , { id: 6, taxNumber: '78684747', name: 'JOAQUIN ANDRADE SANDOVAL' } ] function listPaddockManagersByName() { return paddockManagers.map((paddockManager) => addockManager.name + paddockManager.taxNumber) };
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Use Array.sort y String.localCompare para ordenar la matriz lexográficamente (por la propiedad de name ), luego asigne el resultado para obtener la propiedad taxNumber .

 const paddockManagers = [ { id: 1, taxNumber: '132254524', name: 'JUAN TAPIA BURGOS'}, { id: 2, taxNumber: '143618668', name: 'EFRAIN SOTO VERA'}, { id: 3, taxNumber: '78903228', name: 'CARLOS PEREZ GONZALEZ'}, { id: 4, taxNumber: '176812737', name: 'ANDRES VIÑALES CIENFUEGOS'}, { id: 5, taxNumber: '216352696', name: 'OSCAR PEREZ ZUÑIGA'}, { id: 6, taxNumber: '78684747', name: 'JOAQUIN ANDRADE SANDOVAL' } ]; const result = paddockManagers.sort((a, b) => a.name.localeCompare(b.name)).map(e => e.taxNumber) console.log(result);

about 4 years ago · Juan Pablo Isaza Report

0

El método de clasificación cambiará el orden inicial de su matriz.
Si desea conservar este orden inicial, primero debe duplicar su matriz ( .map() )

 const paddockManagers = [ { id: 1, taxNumber: '132254524', name: 'JUAN TAPIA BURGOS' } , { id: 2, taxNumber: '143618668', name: 'EFRAIN SOTO VERA' } , { id: 3, taxNumber: '78903228', name: 'CARLOS PEREZ GONZALEZ' } , { id: 4, taxNumber: '176812737', name: 'ANDRES VIÑALES CIENFUEGOS' } , { id: 5, taxNumber: '216352696', name: 'OSCAR PEREZ ZUÑIGA' } , { id: 6, taxNumber: '78684747', name: 'JOAQUIN ANDRADE SANDOVAL' } ] const listPaddockManagersByName = arr => arr .map(row=>row) .sort((a,b)=>a.name.localeCompare(b.name)) .map(({name,taxNumber}) => `${name}, ${taxNumber}`) let result = listPaddockManagersByName( paddockManagers ) console.log( paddockManagers ) console.log( result )
 .as-console-wrapper { max-height: 100% !important; top: 0 }

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!