Skip to content
Advertisement

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

Advertisement

Answer

  arr.map(student=>{
     student[3]= student[3].filter(subject=>subject[1]!==null)
     return student
  })
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement