Checking objects from database response

Hi I have the following code:

const material = await company.materials().where(‘id’, id).fetch();

I need to check if there is data in the material variable, if I write it to console I get [] but if I try Array.isArray(material) I get false, how can I check if queries return valid data?

This is never true although it prints out []:
if(material === [] )

Welcome!

if (Array.isArray(material.rows)) {
  console.log("yes");
}

// or like this
if (Array.isArray(material.toJSON())) {
   console.log("yes too");
}

hope will help

HI It worked :slight_smile: Thank you very much!

@nonni Please remember to mark answers as solution, so that it can help others in future. I did it this time :slight_smile:

1 Like

Thanks, will do next time :slight_smile: