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

199
Visualizações
Use arrays' position as function parameters

I'm trying to pass positions of a list of arrays in a function, but I'm definitely missing something.

This is my script :

// function to display the results 
function display(array){                                 
  var source = SpreadsheetApp.openById("x");
  var sheet = source.getSheetByName('x')
  var value = sheet.getRange("G4:I4").setValue(array[x][y]) //sets the range to the value 
}

// function that creates or searches for the array
function recherche() {
  var source = SpreadsheetApp.openById("x");
  var sheet = source.getSheetByName('x')
  
  var arrays = [
    [1,2,3,4,5],
    [6,7,8,9,10]
  ]

  display(arrays[0][0]) // first time it is executed it should display arrays[0][0] or 1

  return arrays
}

// function to display the next value 
function next(){
  var source = SpreadsheetApp.openById("x");
  var sheet = source.getSheetByName('x')
  display(recherche()[x+1][0]) // should display arrays[1][0] or 6
}

Am I doing something stupid or did I just miss something?

Thx

about 4 years ago · Santiago Gelvez
1 Respostas
Responde à pergunta

0

There are so many ways to do this:

First:

function myTest() {
  let i = 0;
  let arrays = rechershe();  // will display arrays[0][0]
  i++;
  next(arrays,i);
}

function next(arrays,i) {
  display(arrays[i][0]);
}

Or:

function myTest() {
  let i = 0;
  let arrays = rechershe(); // will display arrays[0][0]
  i++;
  next(arrays[i][0]);
}

function next(value) {
  display(value);
}

Or:

function myTest() {
  let i = 0;
  let arrays = recherche(); // will display arrays[0][0]
  i++;
  function next() {
    display(arrays[i][0]);
  }
  next(); // will display arrays[1][0]
}

And still another:

function myTest() {
  let i = 0;
  let arrays = recherche();
  i++;
  next = () => display(arrays[0][i]);
  next();
  i++;
  next();
}

8:15:58 AM  Notice  Execution started
8:16:00 AM  Info    1
8:16:00 AM  Info    2
8:16:00 AM  Info    3
8:15:59 AM  Notice  Execution completed
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