Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Splice array rows if they have indexOf

I have these rows and want to delete all rows that have cell containing "undefined"

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

So, I need to remove rows 1 and 3

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

With filter, then some on each item which is truthy if none of the items in each array includes undefined (string).

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 ] ]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading