-1

I saved project list data in an array and Im mapping over this array to display the list in the UI, I using .insertAdjacentHTML(), and the project list coming fine in UI except Im getting an unwanted comma , between each project list items in the UI.

How to remove this , from UI ?

const projectHTML = projectDataArray.map((el) => { //projectDataArray is project list array
    return `<div class="row">${el.title}</div>`
}  
document.querySelector(".work_wrapper").insertAdjacentHTML("afterbegin", projectHTML);

Here is the comma coming between each .row:-

enter image description here

3
  • What does the HTML code im browser look like? In what element is the comma? Commented Jan 26, 2023 at 8:35
  • they are coming here: -prnt.sc/RuRbmtHBxPYj Commented Jan 26, 2023 at 8:37
  • Please search throughly before posting. More about searching here. Commented Jan 26, 2023 at 8:44

1 Answer 1

1

You can use the .join() method to remove the unwanted commas between each project list item. The join() method is used to join all elements of an array into a string.

const projectHTML = projectDataArray.map((el) => { 
    return `<div class="row">${el.title}</div>`
}).join('');
document.querySelector(".work_wrapper").insertAdjacentHTML("afterbegin", projectHTML);
Sign up to request clarification or add additional context in comments.

1 Comment

SO has been around for over 14 years now, all the really basic questions (like this one) have been asked and answered previously, they don't need more answers scattered all over the place. Find and mark the duplicate instead. It's important to preventing SO becoming a haystack where needles can't be found, like forums were.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.