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

107
Views
Reduzca una matriz a una matriz 2D con propiedades coincidentes

Si tengo una matriz de objetos con propiedades internas como esta:

 var array = [ { "Structure_SortID": "001.001.003", }, { "Structure_SortID": "001.001.003", }, { "Structure_SortID": "001.001.003", }, { "Structure_SortID": "001.001.003", }, { "Structure_SortID": "001.004.002", }, { "Structure_SortID": "001.004.002", } ];

¿Cómo puedo reducir esta matriz en una sola matriz 2D que contiene 2 matrices de propiedades "Structure_SortID" coincidentes? La salida debe ser:

 var array = [ // Filtered so only 001.004.002 [ { "Structure_SortID": "001.001.003", }, { "Structure_SortID": "001.001.003", }, { "Structure_SortID": "001.001.003", }, { "Structure_SortID": "001.001.003", } ], // Filtered so only 001.004.002 [ { "Structure_SortID": "001.004.002", }, { "Structure_SortID": "001.004.002", } ] ];

La solución debe permitir un número infinito de listas con propiedades "Structre_SortID" coincidentes. Y necesita admitir situaciones en las que solo hay 1 matriz de ID coincidentes dentro de la matriz 2D. Y debe admitir matrices vacías o matrices de un solo elemento junto con listas coincidentes dentro de la matriz 2D.

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

0

function getArrayOfObjectByKey(data, key) { return Object.values( data.reduce((acc, e) => { if (key in e) { let value = e[key]; if (value in acc) { acc[value].push(e); } else { acc[value] = [e]; } } return acc; }, {}) ); } getArrayOfObjectByKey(array, 'Structure_SortID');
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!