I have been trying to check if a result query is empty or not, I have researched for a while now. The code below shows the query that I'm making and the two ways that I checked if it's empty or not.
The problem is only one block is executed and the other is not executed even if it's supposed to be executed.
db.each(`SELECT category FROM categories WHERE category = ?`, [category], (err, res) => {
if (res != {}) {
console.log("Not Empty")
}else{
console.log(" Empty")
}
}
On the above, if the res returns something it executes the if statement, otherwise the else is not executed.
I have also tried using Objects.keys(res).lenght > 0, but still nothing.
can you please help me understand this better I'm new to node JS.
Like Barmar said it is an array that you get back so you can use
if (res && res.length > 0)