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

164
Views
.join causing an error that says it is not a function

I have this in the firestore where "1" is a map with selected. If it exist, it won't cause any error. But if it does not exist, it says that .join is not a function.

user[1]?.selected?.join(", ")

This is what it looks like in firestore

enter image description here

Will this be fine, I've made a workaround on this one?

{user[1]?.selected ? (
                          <>
                            {" "}
                            <ListItemText
                              primary={user[1]?.selected.join(", ")}
                            />
                          </>
                        ) : (
                          <></>
                        )}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Your issue is because - even if it exists, it's not an Array.
Has to be an Array in order to use the Array.prototype.join()

const user = {
  1: {selected: [1, 2, 4]},
  2: {},
  3: {selected: "test this"},  // << Uncaught TypeError
};

console.log( user[1]?.selected?.join(", ") ); // "1, 2, 4"
console.log( user[2]?.selected?.join(", ") ); // undefined
console.log( user[3]?.selected?.join(", ") ); // Uncaught TypeError 

so, Uncaught TypeError because you cannot use .join() on String primitive

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!