Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to remove unwanted comma (,) from insertAdjacentHTML object?

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

enter image description here

>Solution :

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);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading