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

142
Visualizações
How can I detect if nothing is selected in MySql?

I was working on simple command which checks if there is a specific data in MySql table. First, I tried console.log(result):

const checksql = "SELECT * FROM web_editor_data where name='somename'";
connection.query(checksql, (err, result, fields) => {
  console.log(checksql);
}

It logged [].
Therefore, I tried:

const checksql = "SELECT * FROM web_editor_data where name='somename'";
connection.query(checksql, (err, result, fields) => {
  console.log(checksql == []);
}

However, it logged false.
Is there anything wrong with my code? Or is there a more effective alternative for this?

Thanks in advance.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

checksql == []

This is a great guess, unfortunately in Javascript when comparing arrays and objects, they are not compared by value (what they contain) but if the are literally the same thing.

So checksql is only identical to checksql, which is why this doesn't work. [] is a different array, and if you add an item to [] it doesn't automatically get added to checksql too.

The typical way to just see if something is empty, is by counting the number of items.

You can do this with the length property:

checksql.length === 0; // If true, array is empty
about 4 years ago · Juan Pablo Isaza 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