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

141
Views
JS - Filtrado de matrices anidadas

¿Hay alguna forma en JS de filtrar los valores de matriz anidados?

El resultado deseado es filtrar valores nulos en una matriz anidada.

Probé el siguiente código, pero no es correcto.

 const test = [ [ null, { "start_time": "2022-08-25T08:45:00.000Z", "end_time": "2022-08-25T09:45:00.000Z" }, null, null, null, null, { "start_time": "2022-08-25T10:00:00.000Z", "end_time": "2022-08-25T11:00:00.000Z" }, ] ] let arr = test.filter(item => { return item != null; }) console.log(arr);
about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Puede usar Array#map antes Array#filter de la siguiente manera:

 const test = [ [ null, { "start_time": "2022-08-25T08:45:00.000Z", "end_time": "2022-08-25T09:45:00.000Z" }, null, null, null, null, { "start_time": "2022-08-25T10:00:00.000Z", "end_time": "2022-08-25T11:00:00.000Z" }, ] ] const arr = test.map( items => items.filter(item => { return item !== null; }) ); console.log(arr);

about 4 years ago · Santiago Trujillo Report

0

Por supuesto, puedes reducir la cantidad de código.

 const test = [[null,{"start_time": "2022-08-25T08:45:00.000Z","end_time": "2022-08-25T09:45:00.000Z"},null,null,null,null,{"start_time": "2022-08-25T10:00:00.000Z","end_time": "2022-08-25T11:00:00.000Z"}]]; const arr = test.map(e => e.filter(Boolean)); console.log(arr);
 .as-console-wrapper { max-height: 100% !important; top: 0 }

about 4 years ago · Santiago Trujillo 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!