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

143
Vistas
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 Respuestas
Responde la pregunta

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