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

168
Views
Empalme las filas de la matriz si tienen indexOf

Tengo estas filas y quiero eliminar todas las filas que tienen celdas que contienen "indefinido"

 "rows":[ [0,"Peter", "undefined value"], [3,"John", 90909090], [5,"Mary","undefined"] ]

Entonces, necesito eliminar las filas 1 y 3

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

0

solo usa filtro

 let rows = [ [0, 'Peter', undefined], [3, 'John', 90909090], [5, 'Mary', undefined], ]; rows = rows.filter((row) => { return row.indexOf(undefined) === -1; }); console.log(rows); // [ [ 3, 'John', 90909090 ] ]

si quiere decir que elimine la matriz si tiene una celda de cadena que contiene 'indefinido' como cadena , puede ir con esto

 let rows = [ [0, 'Peter', 'undefined value'], [3, 'John', 90909090], [5, 'Mary', 'undefined'], ]; rows = rows.filter((row) => { let isContainUndefined = false; row.forEach((element) => { if (String(element).includes('undefined')) { isContainUndefined = true; return; } }); return !isContainUndefined; }); console.log(rows); // [ [ 3, 'John', 90909090 ] ]
about 4 years ago · Juan Pablo Isaza Report

0

Con filter , luego algunos en cada elemento que es verdadero si ninguno de los elementos en cada matriz incluye undefined (cadena).

 let rows = [ [0, "Peter", "undefined value"], [3, "John", 90909090], [5, "Mary", "undefined"] ]; rows = rows.filter(row => !row.some(v => typeof v === 'string' && v.includes('undefined'))); console.log(rows); // [ [ 3, 'John', 90909090 ] ]

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!