• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
    • Questions
    • Teachers
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

533
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;
    })
almost 3 years ago · Juan Pablo Isaza
2 answers
Answer question

0

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

almost 3 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)

almost 3 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 Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error