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 on
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 on
['Victor', 'Zuzou', 'Aliyu', 'Sodiq']

Build Anything...


Use any Linode offering to create something for the DEV x Linode Hackathon 2022. A variety of prizes are up for grabs, inculding $1,000 USD. 👀

Join the Hackathon <-