for in loop js strings code example
Example 1: javascript loop through string
for (var i = 0; i < str.length; i++) {
console.log(str.charAt(i));
}
Example 2: for item loop
const object = {a: 1, b: 2, c: 3};
for (const property in object) {
console.log(`${property}: ${object[property]}`);
}
// expected output:
// "a: 1"
// "b: 2"
// "c: 3"