js forin code example
Example 1: javascript for
let str = "";
for (let i = 0; i < 9; i++) {
str = str + i;
}
console.log(str);
Example 2: javascript loop through object
for (var property in object) {
if (object.hasOwnProperty(property)) {
}
}
Example 3: for of js
let panier = ['fraise', 'banane', 'poire'];
for (const fruit of panier) {
console.log(panier.indexOf(fruit));
}
Example 4: for in javascript
const object = {a: 1, b: 2, c: 3};
for (const property in object) {
console.log(`${property}: ${object[property]}`);
}
Example 5: for of loop javascript
const array1 = ['a', 'b', 'c'];
for (const element of array1) {
console.log(element);
}
Example 6: forin js
let panier = ['fraise', 'banane', 'poire'];
for (const fruit in panier) {
console.log(panier[fruit]);
}