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

216
Views
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

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

0

  arr.map(student=>{
     student[3]= student[3].filter(subject=>subject[1]!==null)
     return student
  })
about 4 years ago · Juan Pablo Isaza Report

0

using loop

for (let i = 0; i < arr.length; i++) {
    if( arr[i].indexOf(null) !== -1 ) {
        let iIndex = arr[i].indexOf(null);
        arr[i][j].splice(iIndex, 1);
    } else {
        for (let j = 0; j < arr[i].length; j++) {
            if(arr[i][j]) {
                if ( arr[i][j].indexOf(null) !== -1 ) {
                    let jIndex = arr[i][j].indexOf(null);
                    arr[i][j].splice(jIndex, 1);
                } else {
                    for (let k = 0; k < arr[i][j].length; k++) {
                        if(arr[i][j][k]) {
                            if ( arr[i][j][k].indexOf(null) !== -1 ) {
                                let kIndex = arr[i][j][k].indexOf(null);
                                arr[i][j][k].splice(kIndex, 1);
                            } else {
                                arr[i][j][k]
                            }
                        } else {
                            arr[i][j];
                        }
                    }
                }
            } else {
                arr[i];
            }
        }
    }
}

Result array:

arr = [ [ "studentname1", "id", "school", [[ "subject1", "result1" ], [ "subject2" ]]],
    [ "studentname2", "id", "school", [[ "subject1", "result1" ], [ "subject2", "result2" ]]] ]
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!