Languages
[Edit]
EN

JavaScript - iterate through string

3 points
Created by:
elmer
646

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

References

Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

Cross technology - iterate through string

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join