Answers for "ts iterate through object keys"

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 "ts iterate through object keys"

Code answers related to "Javascript"

Browse Popular Code Answers by Language