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

201
Views
How to avoid .map skipping white spaces?

Got an issue. Need to put full name from array as ID of LI element. ATM it takes only first word for some reason.could you help?

const buddiesNames = ['RGX 11z Pro Buddy', 'Zedd Buddy', 'Get Carried Buddy', 'In A Bind Buddy', 'Year One Buddy'];

ulForBuddyNames.innerHTML = buddiesNames
  .map(
    (elem) =>
      `<li " class="valorantHeroBuddy"><a href="#"  onClick="showCharacterBuddy(event)" id=${elem}>  ${elem}<a/></li>`
  )
  .join('');

https://codepen.io/DeanWinchester88/pen/LYjmgyQ

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Can't have spaces in an id. Try replacing them with a hyphen: elem.replace(/\s+/, '-')

id's value must not contain whitespace (spaces, tabs etc.). Browsers treat non-conforming IDs that contain whitespace as if the whitespace is part of the ID. In contrast to the class attribute, which allows space-separated values, elements can only have one single ID value.

  • MDN

var ulForBuddyNames = document.querySelector('div');
const buddiesNames = ["RGX 11z Pro Buddy", "Zedd Buddy", "Get Carried Buddy", "In A Bind Buddy", "Year One Buddy"];
ulForBuddyNames.innerHTML = buddiesNames.map(elem => `<li class="valorantHeroBuddy"><a href="#"  onClick="showCharacterBuddy(event)" id=${elem.replace(/\s+/, '-')}>  ${elem}<a/></li>`).join("");
<div></div>

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!