loop on each character js 1

loop on each character js

for (var i = 0; i < str.length; i++) {
  alert(str.charAt(i));
}

Here is what the above code is Doing:
1. We create a variable called str and assign it the value of "Hello World".
2. We create a for loop that will run as long as i is less than the length of the string.
3. We create an alert that will display the character at the index of i.
4. We increment i by 1.
5. We repeat steps 2-4 until i is no longer less than the length of the string.

Similar Posts