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:
// ONLINE-RUNNER:browser;
let text = 'ABCD';
for (let i = 0; i < text.length; i++) {
console.log(text.charAt(i));
}
Alternative solution
In this example, we use for...of
loop to iterate through each character of the text
string.
// ONLINE-RUNNER:browser;
const text = 'ABCD';
for (const character of text) {
console.log(character);
}
Output:
A
B
C
D