Answers for "how to get the keys from an object in for loop javascript"

1

loop key in object

const fruits = { apple: 28, orange: 17 }

for(key in fruits){
	console.log(key)
}
Posted by: Guest on June-29-2020
1

js loop through object keys

for (const value of Object.values(obj)) { }
Posted by: Guest on October-26-2021
0

Iterate Through the Keys of an Object

// Iterate Through the Keys of an Object

const usersObj = {
  Alan: {
    online: false,
  },
  Jeff: {
    online: true,
  },
  Sarah: {
    online: false,
  },
};

function countOnline(usersObj) {
  let count = 0;
  for (let user in usersObj) {
    if (usersObj[user].online === true) count++;
  }
  return count;
}

console.log(countOnline(usersObj));
Posted by: Guest on January-02-2022

Code answers related to "how to get the keys from an object in for loop javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language