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

171
Views
dividir y aplanar una matriz de cadenas separadas por comas

Cuál es la mejor manera de convertir:

 const a = ["jan,feb,may", "apr,may,sept,oct", "nov,jan,mar", "dec", "oct,feb,jan"]

a

 const res = ["jan","feb","may","apr","may","sept","oct","nov","jan","mar","dec","oct","feb","jan"]

PD: en javascript, intenté usar array.reduce() y el método split. pero eso no funcionó. esto es lo que probé

 let flat = arr.reduce((arr, item) => [...arr, ...item.split(',')]);
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Usando Array#flatMap y String#split :

 const a = ["jan,feb,may", "apr,may,sept,oct", "nov,jan,mar", "dec", "oct,feb,jan"]; const res = a.flatMap(e => e.split(',')); console.log(res);

about 4 years ago · Juan Pablo Isaza Report

0

En este caso, podría simplemente unirse y dividirse nuevamente:

 const a = ["jan,feb,may", "apr,may,sept,oct", "nov,jan,mar", "dec", "oct,feb,jan"]; const res = a.join().split(','); console.log(res);

O uniéndose implícitamente:

 const a = ["jan,feb,may", "apr,may,sept,oct", "nov,jan,mar", "dec", "oct,feb,jan"]; const res = "".split.call(a, ","); console.log(res);

O unirse implícitamente al dividir con un método regex :

 const a = ["jan,feb,may", "apr,may,sept,oct", "nov,jan,mar", "dec", "oct,feb,jan"]; const res = /,/[Symbol.split](a); console.log(res);

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!