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

153
Visualizações
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 Respostas
Responde à pergunta

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 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