Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

166
Vistas
.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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda