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

224
Views
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 answers
Answer question

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 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!