Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

89
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda