Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

146
Vistas
How to check if nested array does not contain a certain array?

This code checks the background of a certain number of cells.

var array = sheet.getRange(1, 1, 20, 1).getBackgrounds();

If I log this array in the Google Apps Script console, it returns the following array:

[[#cccccc], [#ffffff], [#ffffff], [#ffffff], [#ffffff], [#cccccc], [#ffffff], [#ffffff], [#ffffff], [#ffffff], [#f3f3f3], [#ffffff], [#ffffff], [#ffffff], [#ffffff], [#ffffff], [#cccccc], [#cccccc], [#ffffff], [#ffffff]]

I want to check if this array does not contain a certain color code: #377a47.

I tried to use includes for this, however this does not work as the value is an array and not a string.

console.log(!array.includes("#377a47")); // returns true

This should return true, as the array does not contain this #377a47 color code. And it does return true, however it also returns true if I try the following color code that is present in the array:

console.log(!array.includes("#cccccc")); // returns true

So apparently this is not the right way to check if the array does not contain #377a47. I suspected it had something to do with the fact it is a nested array, but am not sure how to correctly write the code to check this.

My Question: How to correctly check if the array does not contain the color code #377a47?

about 4 years ago · Santiago Gelvez
1 Respuestas
Responde la pregunta

0

Arrays in JavaScript are compared by reference so even approach:

array.includes(["#377a47"]) //returns false

won't work

You can try flattening an array and compare primitive values like this:

console.log(![[1], [2], [3]].flat().includes(1)); //returns false
about 4 years ago · Santiago Gelvez Denunciar
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 Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda