Answers for "string loop in javascript"

9

javascript loop through string

for (var i = 0; i < str.length; i++) {
  console.log(str.charAt(i));
}
Posted by: Guest on June-01-2020
1

loop through string javascript

const str = "Hello Grepper!";
const chars = [...str];
chars.forEach((c, i) => console.log(c, i));
Posted by: Guest on October-10-2021
9

for of loop javascript

const array1 = ['a', 'b', 'c'];

for (const element of array1) {
  console.log(element);
}

// expected output: "a"
// expected output: "b"
// expected output: "c"
Posted by: Guest on March-02-2020
0

javascript loop through array

// looping through an array in javascript using our own myEach function

// Write an `Array.prototype.myEach(callback)` method that invokes a callback
// for every element in an array and returns undefined.
Array.prototype.myEach = function(callback) {
    for (let i = 0 ; i < this.length ; i ++) {
        callback(this[i]);
    }
}

let array = ['Item 1', 'Item 2', 'Item 3', 'Item 4'];

array.myEach(function (element) {
	console.log(element); // this will print each element in the array
    // Code to do something to each element in the array
});
Posted by: Guest on October-24-2020

Code answers related to "string loop in javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language