loading...

Javascript Object.keys( ) method

victoromondi1997 profile image VICTOR OMONDI ・1 min read

Want to get all keys present in an object?

Try Object.keys( )

Usecase:

let obj = {
    year: 2019,
    month: 'september'
}

const objKeys = Object.keys(obj);            

console.log(objKeys);

// [ 'year', 'month' ]

Discussion

pic
Editor guide
 
let users = {
  Victor: {
    age: 27,
    online: false
  },
  Zuzou: {
    age: 32,
    online: true
  },
  Aliyu: {
    age: 48,
    online: false
  },
  Sodiq: {
    age: 19,
    online: true
  }
};

function getArrayOfUsers(obj) {

   return Object.keys(obj);

}

console.log(getArrayOfUsers(users));```


 
['Victor', 'Zuzou', 'Aliyu', 'Sodiq']