Horje
Iterate Through the Keys of an Object Code Example
iterate key value object javascript
'use strict';
// ECMAScript 2017
const object = {'a': 1, 'b': 2, 'c' : 3};
for (const [key, value] of Object.entries(object)) {
  console.log(key, value);
}
loop key in object
const fruits = { apple: 28, orange: 17 }

for(key in fruits){
	console.log(key)
}
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));




Javascript

Related
set a variable in express.js Code Example set a variable in express.js Code Example
Sort big numbers from an array in javascript Code Example Sort big numbers from an array in javascript Code Example
convert js to python online Code Example convert js to python online Code Example
update array of object using other array javascript Code Example update array of object using other array javascript Code Example
angular $http abort request Code Example angular $http abort request Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
6