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

146
Visualizações
Google script loop stops at first match

I want to search for a similar name, not exact in google sheet. Which function is case insensitive and does not exactly match? e.g. If my column contains names of places Delhi, New Delhi, South Delhi, North Delhi then my Search for Delhi should list all 4. However, the loop stops at the 1st match.

function search(e){
 var id = e.parameter.id;
  
  var values = sheet.getRange(2, 1, sheet.getLastRow(),sheet.getLastColumn()).getValues();
  
  for(var i = 0;i<values.length; i++){
    
    if(values[i][0] == id || values[i][1] == id ){
      i=i+2;
      
      var Airport = sheet.getRange(i,3).getValue();
      return ContentService.createTextOutput(Airport).setMimeType(ContentService.MimeType.TEXT);
    }
  }
  return ContentService.createTextOutput("Id not found").setMimeType(ContentService.MimeType.TEXT);
about 4 years ago · Santiago Gelvez
1 Respostas
Responde à pergunta

0

Try this:

function search(e) {
  var id = e.parameter.id;
  var values = sheet.getRange(2, 1, sheet.getLastRow() - 1, sheet.getLastColumn()).getValues();
  let a = [];
  for (var i = 0; i < values.length; i++) {
    if (values[i][0] == id || values[i][1] == id) {
      a.push(values[i][2]);
    }
  }
  if(a) return ContentService.createTextOutput(a.join(',')).setMimeType(ContentService.MimeType.TEXT);
  return ContentService.createTextOutput("Id not found").setMimeType(ContentService.MimeType.TEXT);
}
about 4 years ago · Santiago Gelvez 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