• Empleos
  • Sobre nosotros
  • profesionales
    • Inicio
    • Empleos
    • Cursos y retos
  • empresas
    • Inicio
    • Publicar vacante
    • Nuestro proceso
    • Precios
    • Evaluaciones
    • Nómina
    • Blog
    • Comercial
    • Calculadora de salario

0

106
Vistas
Logger.log(cell.indexOf() always showing -1

I am using a function that fetches values from a range, for this example ["red", "blue", "green"]

function readDataFromRange() {
  var sheet = SpreadsheetApp.getActive();
  var range = sheet.getRange("A:A");
  var cell = range.getValues();
  
  Logger.log(cell[2]);
  Logger.log(cell.length);
  Logger.log(cell.indexOf("green"));

}

this is the result

Execution log

3:23:17 AM  Notice  Execution started
3:23:17 AM  Info    [green]
3:23:17 AM  Info    1000.0
3:23:17 AM  Info    -1.0
3:23:17 AM  Notice  Execution completed

although at index 2 it shows green if ask the index of green it shows -1 and same goes for red and blue any idea why this is happening ?

about 3 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recomiéndame algunas ofertas
Necesito ayuda