Search code snippets, questions, articles...

Get all keys from an object using Javascript

You can use Object.keys() method to get all keys from an object. It will return the array of key names.
var obj = {
    "name": "Ankit",
    "username": "ankit01",
    "status": "active",
    "contact": "mail"
};

var all_keys = Object.keys(obj);
Output
["name","username","status","contact"]

Live Demo

Search Index Data (The code snippet can also be found with below search text)

Object.keys javascript
Was this helpful?
0 Comments
Programming Feeds
Learn something new everyday on Devsheet