EN
JavaScript - iterate through string
3 points
In this article, we would like to show you how to iterate through string characters in JavaScript.
Quick solution:
xxxxxxxxxx
1
let text = 'ABCD';
2
3
for (let i = 0; i < text.length; i++) {
4
console.log(text.charAt(i));
5
}
In this example, we use for...of
loop to iterate through each character of the text
string.
xxxxxxxxxx
1
const text = 'ABCD';
2
3
for (const character of text) {
4
console.log(character);
5
}
Output:
xxxxxxxxxx
1
A
2
B
3
C
4
D