![]() There exists a special form of the loop: for.in. ![]() To walk over all the characters of a string, we can use an ordinary for loop, with a loop counter ( i) to go through string index from 0 to str.length: // ordinary for loop let str = "Buzz" Use the string index number to loop through a string for loop There is no need to add brackets after it. ![]() Please note that str.length is a numeric property, not a function. The length property has the string length, it simply returns the number of characters in the string: let str = "hello123" Īlert(str.length) // 8 // the last character Looping Through a String The length Property
0 Comments
Leave a Reply. |