js for i in code example
Example 1: javascript for
let str = "";
for (let i = 0; i < 9; i++) {
str = str + i;
}
console.log(str);
Example 2: loop an object in javascript
var obj = { first: "John", last: "Doe" };
Object.keys(obj).forEach(function(key) {
console.log(key, obj[key]);
});
Example 3: for in loop javascript
var person = {"name":"taylor","age":31};
for (property in person) {
console.log(property,person[property]);
}
Example 4: for in loop javascript
let array = [1,2,3,4,5,6,7,8,9,10];
for (let i = 0; i < array.length; i++) {
console.log(array[i]);
}
Example 5: for in javascript
const object = { a: 1, b: 2, c: 3 };
for (const property in object) {
console.log(`${property}: ${object[property]}`);
}