javascript - Apps Script "OR" logical operator - Stack Overflow

admin2025-04-17  0

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

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

Share edited Mar 12, 2022 at 0:53 Wicket 38.8k9 gold badges80 silver badges195 bronze badges asked Mar 11, 2022 at 23:33 Progress Point TutoringProgress Point Tutoring 391 silver badge7 bronze badges 3
  • 1 tutorNames.filter(row=>row[0]=="0" || row[0] == "1").map(row => row [13]) – Cooper Commented Mar 12, 2022 at 0:28
  • It might allso be tutorNames.filter(row=>row[0] == 0 || row[0] == 1).map(row => row [13]) – Cooper Commented Mar 12, 2022 at 0:30
  • how about tutorNames.filter(row=>parseInt(row[0] < 2)).map(row => row [13]) – Cooper Commented Mar 12, 2022 at 0:32
Add a ment  | 

1 Answer 1

Reset to default 4

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

  • https://developer.mozilla/en-US/docs/Web/JavaScript/Reference/Operators/Logical_OR
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1744884502a272457.html

最新回复(0)