for.. loop in JavaScript

dindustack

Chinwendu Agbaetuo

Posted on April 11, 2024

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
💖 💪 🙅 🚩
dindustack
Chinwendu Agbaetuo

Posted on April 11, 2024

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related