JavaScript Code

How to loop over the keys of an object?


Problem Statement

loop over the keys of an object

Solution

for…in loop can be used to iterate over the keys of an object. during each iteration we can access the respective key of the object

Program

const student = {
    name: 'Anita',
    class: 5,
    age: 11,
    nationality: 'India'
}

for ( let key in student ) {
    console.log(key);
}