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

231
Visualizações
How can I make a variable the name of an element from firebase and alter the new variable?

I'm working on a drive thru app project that uses firebase and JavaScript to display the menu information. I planned to use a template text for displaying everything and it all worked fine. I was even able to make a variable = the value of a field in firebase, but I'm unable to alter that new value. I wanted to replace all spaces with underscores since that is how I named the pictures in my project but it seems to just ignore this command. Here is the code:

let itemName = menuItem.name;
itemName.replace(" ", "_");
console.log(itemName);

Does anyone know of a solution to this?

about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Javascript's String.prototype.replace function doesn't edit strings in-place, it creates a new one. As well, when doing simple string replacement, it only replaces the first instance - you want replaceAll. This code will do what you want:

let itemName = menuItem.name;
let newName = itemName.replaceAll(" ", "_");
console.log(newName);
about 4 years ago · Santiago Trujillo 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