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

88
Views
Array from GroupsApp and then indexOf fails

I am trying to get a list of people in a Google Group with Google Apps Script. I made a code (below) but the result is unexpected. I think is realted with the format of the item but not sure. In my code i tested many logs to check that.

Why "indexOf" can not detect properly the email? Becuase -1.00 as answer is wrong.

Info: getUsers() User[] Retrieves the direct members of the group that have a known corresponding Google account.

I think is weird indexOf answering -1.00 when i ask with "" and when i ask with the position of array answer properly.

I need to check in an script if someone is inside of this groups (inside loop for).

function CheckingSomeFromGroup() {
  var members = GroupsApp.getGroupByEmail("members@company").getUsers();

  Logger.log(members); //it shows an array in the log
  Logger.log(members[0]); //it shows the first element form that array which is "Jorge@company.com"
  Logger.log(members.indexOf("Jorge@company.com") //i was expecting a number different than -1.00 because jorge exists but in the log appear -1.00 which is wrong
  Logger.log(members.indexOf(members[0]); //it shows 0 correctly becuase Jorge is in the first place of the array
  Logger.log(members.length);//it shows number 3 which is ok since i have 3 people in the group

}

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

0

members is an array of User object, not string. So you cannot just find it by email/string. You see email in the logger because it might have a toString method to output that.

You can loop on members and call User.getEmail() to get the email and work accordingly.

function CheckingSomeFromGroup() {

    var emails = ['abc@example.com'];//get 1-D array of string emails from your column accordingly

    var members = GroupsApp.getGroupByEmail("members@company").getUsers();

    for (var i = 0; i < members.length; i++) {
        var memberEmail = members[i].getEmail();

        if (emails.indexOf(memberEmail) !== -1) {
//exists
        }

    }

}
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!