xxxxxxxxxx
// for in loop javascript
const obj = {
a: 'chetan',
b: 'ujesh'
}
for(let key in obj){
console.log(obj[key]);
//chetan
//ujesh
}
xxxxxxxxxx
var person = {"name":"taylor","age":31};
for (property in person) {
console.log(property,person[property]);
}
xxxxxxxxxx
const book = {
title: "Harry Potter and The Philosopher's Stone",
author: "J. K. Rowling",
year: 1997
};
for (x in book) {
console.log(x, ':', book[x]);
}
xxxxxxxxxx
let arry = {
name: "Rakibul Islam",
class: "Tane",
grup: "A",
roll: 10,
sub: "Arse"
}
//for in loop used to object
for(let i in arry){
console.log(i,arry[i]);
}
xxxxxxxxxx
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"
xxxxxxxxxx
const p = {
"p1": "value1",
"p2": "value2",
"p3": "value3"
};
for (let [key, value] of Object.entries(p)) {
console.log(`${key}: ${value}`);
}
xxxxxxxxxx
var car = {"Tesla":"Model 3", "Mercedes":"V-8 Model"};
for(brandName in car){
console.log(brandName);
}
//Tesla
//Mercedes
for(brandName in car){
console.log(car[brandName]);
}
//Model 3
//V-8 Model
xxxxxxxxxx
var obj = {a: 1, b: 2, c: 3};
for (const prop in obj) {
console.log(`obj.${prop} = ${obj[prop]}`);
}
// Output:
// "obj.a = 1"
// "obj.b = 2"
// "obj.c = 3"
xxxxxxxxxx
var colors=["red","blue","green"];
for(let col of colors){
console.log(col);
}
// red
// blue
// green