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

234
Visualizações
For loop and If statement in a list google apps script

I'm friendly with python, but I need the same code in google apps script. ( the code is under the text)

Thank you in advance

I need my output like this :

plus = [[600, 'ter', 'simple'], [600, 'ter', 'simple']]

Here's my code :

      function myFunction() {
  
          var data =[[600, 'ter', 'simple'], [600, 'ter', 'simple'], [300, 'ter', 'medium'], [200, 'ter', 'Hard']]

          var plus  = []

          for (let i = data[0]; i < data.leng; i++)
          {
            if ( data[i][0] == data[0][0])
            {
              plus.push(data)
            }
          }
        }
about 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

Couple of syntax mistakes here and there. Pointed them in code:

/*<ignore>*/console.config({maximize:true,timeStamps:false,autoScroll:false});/*</ignore>*/
function myFunction() {
  var data = [
    [600, 'ter', 'simple'],
    [600, 'ter', 'simple'],
    [300, 'ter', 'medium'],
    [200, 'ter', 'Hard'],
  ];
  var plus = [];
  for (
    let i = 0 /* intializer or counter should start with 0 not data[0]  */;
    i < data.length /* No property named leng data.leng */;
    i++
  ) {
    if (data[i][0] == data[0][0]) {
      plus.push(
        data[
          i
        ] /* push only the current element  `data[i]` and not the full `data` array */
      );
    }
  }
  console.log(plus);
}
myFunction();
<!-- https://meta.stackoverflow.com/a/375985/ -->    <script src="https://gh-canon.github.io/stack-snippet-console/console.min.js"></script>

about 4 years ago · Santiago Trujillo Relatório

0

Use Array.filter(), like this:

function filterData() {
  const data = [
    [600, 'ter', 'simple'],
    [600, 'ter', 'simple'],
    [300, 'ter', 'medium'],
    [200, 'ter', 'Hard'],
  ];
  const filterBy = { column: 0, value: data[0][0] };
  return data.filter(row => row[filterBy.column] === filterBy.value);
}

about 4 years ago · Santiago Trujillo 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