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);
});
// Every one single answer
//1
var value = "alma";
var new_value = [...value].map((x) => x+"E").join("")
//2
let str = 'This is my string';
for(let character of str) // secondary performance
console.log(character)
//3
for (var i = 0; i < str.length; i++) { // most performance
alert(str.charAt(i));
}
//4
for (var i = 0; i < str.length; i++) {
alert(str[i]);
}
//5
var i = str.length;
while (i--) {
alert(str.charAt(i));
}
//6
var i = str.length;
while (i--) {
alert(str[i]);
}
//7
// ES6 version.
let result = '';
str.split('').forEach(letter => { // almost third at performance
result += letter;
});
//8
var result = '';
for (var letterIndex in str) {
result += str[letterIndex];
}