for in nodejs code example

Example 1: for loop in node js

var i;
for (i = 0; i < cars.length; i++) {
  text += cars[i] + "<br>";
}

Example 2: loop an object in javascript

var p = {
    "p1": "value1",
    "p2": "value2",
    "p3": "value3"
};

for (var key in p) {
    if (p.hasOwnProperty(key)) {
        console.log(key + " -> " + p[key]);
    }
}

Example 3: loop an object in javascript

var obj = { first: "John", last: "Doe" };

Object.keys(obj).forEach(function(key) {
    console.log(key, obj[key]);
});

Example 4: forin js

let panier = ['fraise', 'banane', 'poire'];

for (const fruit in panier) {
    console.log(panier[fruit]);
}

Example 5: for in javascript

let items = ['beef', 'cabbage', 'javascript']; // Defines a list of items
for (let item of items) { // Defines for loop with a variable of 'item'
  console.log(item); // Prints the item that is found
}