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

remove row from a row in array if it indexOf null

I have this array:

let arr = [

  ['studentname','id','school', [['subject1', 'result1'],['subject2',null]]],
  ['studentname','id','school', [['subject1', 'result1'],['subject2','result2']]],


]; 

and want to delete the subject and its result if result is null. I mean to delete ['subject2',null] and keep the rest of the array it will be after deleting it

 let arr = [

  ['studentname','id','school', [['subject1', 'result1']]],
  ['studentname','id','school', [['subject1', 'result1'],['subject2','result2']]],


]; 

I get the array dynamically and want to not diplay the subject if the result is null.
I used filter but i get errors like it remove the whole row

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 :

  arr.map(student=>{
     student[3]= student[3].filter(subject=>subject[1]!==null)
     return student
  })
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