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

140
Views
Showing undefined value

I have this table where I fetch the data using firestore. There were some cases where this data is empty. I have this address where city is empty it would show undefined. How would I just display it as blank instead of the word "undefined"?

componentDidMount() {
    firestore
      .collection("users")
      .get()
      .then((snapshot) => {
        const users = [];
        snapshot.forEach((doc) => {
          const data = doc.data();
          users.push({
            "User ID": doc.id,
            Address: data.address + ", " + data.city + ", " + data.provice,
                }),
          });
        });
        this.setState({ users: users });
      })
      .catch((error) => console.log(error));
  }
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

use OR || operator if city is undefined

Address: data.address + ", " + data.city || "" + ", " + data.provice
about 4 years ago · Juan Pablo Isaza Report

0

Instead of using + you can do the following, It will simplify the code readability and cater to your use case.

 Address: `${data.address} , ${data.city || ""} , ${data.provice}`,
about 4 years ago · Juan Pablo Isaza Report

0

You can use nullish coalescing operator.

data.city ?? ""

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!