To iterate over words in a string in JavaScript, you can use the split
method with a space as the delimiter.
In this example,
str
with a value of 'Hello World JavaScript'
.split(' ')
method on the string to split it into words based on spaces.let str = 'Hello World JavaScript';
let words = str.split(' ');
for (let word of words) {
console.log(word);
}
Hello World JavaScript
In this tutorial, we learned How to Iterate over Words in String in JavaScript language with well detailed examples.