Search code examples
javascriptgoogle-apps-scriptor-operator

Apps Script "OR" logical operator


Our "Current Tutors" sheet has a list of tutor names in column N (shown as row [13] in the code). Column A is the # of students they have (row [0]) in the code.

Basically, we want to filter our Google Form choices so that only tutors with values of 0 or 1 in column A appear. Unfortunately, it looks like the "|" does not do the logical operation of 0 OR 1. It just returns tutor names who have 0 students.

We are not savvy with coding, so any down-to-earth explanation is appreciated!

var approvedtutors = tutorNames.filter(row=>row[0]=="0"|"1").map(row => row [13])

Sheet


Solution

  • In Google Apps Script / JavaScript the OR operator is || not |.

    Change

    var approvedtutors = tutorNames.filter(row=>row[0]=="0"|"1").map(row => row [13])
    

    by

    var approvedtutors = tutorNames.filter(row=>row[0]== "0" || row[0] == "1").map(row => row [13])
    

    Reference