DEV Community

Chinwendu Agbaetuo
Chinwendu Agbaetuo

Posted on • Updated on

for.. loop in JavaScript

This is how to output data using Object.entries(parameter). Object.entries() is a method used in getting an array of keys and values from an object. Read more MozillaMDN


let profile = {
    "first name": "Chinwendu",
    "last name": "Agbaetuo",
    "age": 53
};

   const details = Object.entries(profile);

   for(let index = 0; index < details.length; index++) {
      console.log(`My ${details[index][0]} is ${details[index][1]}`)
   }
Enter fullscreen mode Exit fullscreen mode

Result

> "My first name is Chinwendu"
> "My last name is Agbaetuo"
> "My age is 53"
Enter fullscreen mode Exit fullscreen mode

Top comments (0)