Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

596
Views
How to check if Axios response data is empty

How to check if axios response is empty. Sometimes my response. data will be [ ]. Currently, it aways alerts "data there" is there a better way to do this than response.data.length >= 1

return await axios
    .get(url.rest_api + '/team_members', {
      params: {
        primaryOwner: firebase.auth().currentUser.uid,
        teamMemberEmail: emailText,
      },
    })
    .then(response => {
      if (response.data) {
        alert('data there');
      } else {
        alert('nothing here');
      }
      return response.data;
    })
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

you can check the availability with: const isDataAvailable = response.data && response.data.length;

about 4 years ago · Juan Pablo Isaza Report

0

According to the Response Schema, response.data is an instance of an Object (please correct me if I'm wrong). So we can check if data is not an empty string AND if it's constructor is and instance of an Object.

That's how I check it

if (response.data !== '' && response.data.constructor === Object) {
   //do something
}

Never fails (for me at least)

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!