How to Split a String by Comma and Loop Through Using JavaScript
In this lesson, we will see how to split a string by comma and loop through using javascript, so let's assume that we have a string of tags separated by a comma and we want to loop through the string and display each tag separately.
Use the split method
To achieve that we will use the split method and then loop through each tag and console log it.
const tags = "php, javascript, java";
tags.split(',').forEach(tag => {
console.log(tag);
});