JS Loop Over Object
const object = {a: 1, b: 2, c: 3};
for (const property in object) {
console.log(`${property}: ${object[property]}`);
}
Navid2zp
const object = {a: 1, b: 2, c: 3};
for (const property in object) {
console.log(`${property}: ${object[property]}`);
}
var subjects = {
'math': 85,
'physics': 75,
}
for (var i in subjects) {
console.log(i + ' : ' + subjects[i]);
}
// math : 85
// physics : 75
const obj = {
a: 1,
b: 2,
c: 3,
d: 4
}
for (const key in obj) {
console.log( obj[key] )
}
// Result: 1, 2, 3, 4
//basic for in loop
const car = {
carName: "Ford",
carDoor: 4,
carSpeed: 180
}
for (objKey in car) {
console.log(car[objKey])
}
//output
Ford
4
180
const array1 = ['a', 'b', 'c'];
for (const element of array1) {
console.log(element);
}
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]);
}