Author -  Sai gowtham

How to iterate/loop over JavaScript Objects

In this tutorial, we will learn about different ways through iterate/loop over the JavaScript object.

For in Loop

for in loop helps us to get the object keys by using that keys we are outputting the object values.

This below example shows how to iterate over objects by using a for in loop

const obj  = {
   name: "reactgo.com",
   age: 7,
   location: "web"
}

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

// first iteration obj.name = "reactgo.com"
// second iteration obj.age = 7
// third iteration obj.location = "web"

Object.keys method

In es6 we can do it a better way by using Object.keys() method.

Object.keys method takes the object as an argument and it returns back the array of keys.

const obj  = {
   name: "reactgo.com",
   age: 7,
   location: "web"
}

const keys = Object.keys(obj);
console.log(keys); // ['name','age','location']

for(let key of keys){
    console.log(obj.key);
}

Object.values method

It helps us to get the array of object values instead of object keys.


const obj  = {
   name: "reactgo.com",
   age: 7,
   location: "web"
}

const values = Object.keys(obj)
console.log(values); // ['reactgo.com',7,'web']


for(value of values){
    console.log(value);
}

Output:

'reactgo.com'
7
'web'

Css Tutorials & Demos

How rotate an image continuously in CSS

In this demo, we are going to learn about how to rotate an image continuously using the css animations.

How to create a Instagram login Page

In this demo, i will show you how to create a instagram login page using html and css.

How to create a pulse animation in CSS

In this demo, i will show you how to create a pulse animation using css.

Creating a snowfall animation using css and JavaScript

In this demo, i will show you how to create a snow fall animation using css and JavaScript.

Top Udemy Courses

JavaScript - The Complete Guide 2023 (Beginner + Advanced)
JavaScript - The Complete Guide 2023 (Beginner + Advanced)
116,648 students enrolled
52 hours of video content
$14.99 FROM UDEMY
React - The Complete Guide (incl Hooks, React Router, Redux)
React - The Complete Guide (incl Hooks, React Router, Redux)
631,582 students enrolled
49 hours of video content
$24.99 FROM UDEMY
Vue - The Complete Guide (w/ Router, Vuex, Composition API)
Vue - The Complete Guide (w/ Router, Vuex, Composition API)
203,937 students enrolled
31.5 hours of video content
$14.99 FROM UDEMY