js string for loop code example
Example 1: javascript loop through string
for (var i = 0; i < str.length; i++) {
console.log(str.charAt(i));
}
Example 2: loop javascript
//this is javascript
var speed = 100;
setInterval(function() {
//DO SOMETHING THAT REPEATS
},speed);
Example 3: for loop js
let arr = [];
for(let i = 0; i <= 10; i++){
arr[i] = Math.round(Math.random() * 10);
}
• Result: [3, 1, 1, 2, 3, 9, 5, 6, 6, 8, 5]
• Or
let arr = [];
for(let i = 0; i <= 10; i++){
arr[i] = Math.trunc(Math.random() * 10);
}
Result[7, 6, 0, 2, 4, 8, 7, 5, 5, 6, 5]