EN
TypeScript - iterate through string
0
points
In this article, we would like to show you how to iterate through string characters in TypeScript.
Quick solution:
const text: string = '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.
const text: string = 'ABCD';
for (const character of text) {
console.log(character);
}
Output:
A
B
C
D