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

136
Views
Matrices de Javascript en una matriz

Tengo una matriz de articles que tiene matrices de results . Estoy intentando combinar todos estos resultados en una matriz sin los results por ejemplo:

 const articles = [{ "id": 203, "title": "testing"}, {"id": 213,"title": "new title"}, { "id": 1, "title": "one"}, {"id": 2,"title": "two"}, { "id": 32, "title": "test article"}, {"id": 62,"title": "title test"}]

Intenté lograr esto asignando articles pero el resultado devuelto sigue siendo matrices separadas en lugar de 1 matriz de objetos. ¿Cómo puedo conseguir esto?

Aquí está mi fragmento de código:

 const articles = [{results: [{ "id": 203, "title": "testing"}, {"id": 213,"title": "new title"}]}, {results: [{ "id": 1, "title": "one"}, {"id": 2,"title": "two"}]}, {results: [{"id": 62,"title": "title test"}]} ] let mappedArticles = articles.map(article => { return article.results }) console.log(mappedArticles)

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

0

Puedes usar mapa plano

 const articles = [{results: [{ "id": 203, "title": "testing"}, {"id": 213,"title": "new title"}]}, {results: [{ "id": 1, "title": "one"}, {"id": 2,"title": "two"}]}, {results: [{"id": 62,"title": "title test"}]} ] let mappedArticles = articles.flatMap(article => article.results) console.log(mappedArticles)

about 4 years ago · Juan Pablo Isaza Report

0

En caso de que flatMap no sea compatible con su entorno, hay otra forma de lograrlo, aunque un poco más detallada y no trivial, que utiliza el método concat del prototipo Array:

 const articles = [{results: [{ "id": 203, "title": "testing"}, {"id": 213,"title": "new title"}]}, {results: [{ "id": 1, "title": "one"}, {"id": 2,"title": "two"}]}, {results: [{"id": 62,"title": "title test"}]} ] const mappedArticles = articles.reduce((acc, article) => acc.concat(article.results), []); console.log(mappedArticles);

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!