DEV Community

VICTOR OMONDI
VICTOR OMONDI

Posted on

Javascript Object.keys( ) method

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' ]

Enter fullscreen mode Exit fullscreen mode

Top comments (2)

Collapse
 
tabithakavyu profile image
Thabitha Kavyu • Edited
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));```


Collapse
 
victoromondi1997 profile image
VICTOR OMONDI • Edited
['Victor', 'Zuzou', 'Aliyu', 'Sodiq']