JavaScript Code


How to loop over the keys of an object in JavaScript?


Loop over the keys of an object in JavaScript

In this tutorial, you will learn how to iterate over the keys of an object in JavaScript.

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);
}