Answers for "iterate a string using js"

0

string iterate in js

var text = 'uololooo';

// With simple for loop
for(let i=0; i<text.length; i++){
  console.log(text[i])
}

// With ES6
[...text].forEach(c => console.log(c))

// With the `of` operator
for (const c of text) {
    console.log(c)
}

// With ES5
for (var x = 0, c=''; c = text.charAt(x); x++) { 
    console.log(c); 
}

// ES5 without the for loop:
text.split('').forEach(function(c) {
    console.log(c);
});
Posted by: Guest on October-22-2021
1

loop through string js

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

Code answers related to "Javascript"

Browse Popular Code Answers by Language