Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

168
Visualizações
.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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda