Browse By

Get Object’s Keys and Values The Easy Way

By using Object methods keys(), values(), and entries(), you can get an array containing object’s keys, values, and key values arrays respectively

Here is the syntax👇

//Get array of object keys
Object.keys(obj); // ['name', 'type']

//Get array of object values 
Object.values(obj); // ['codehood', 'channel']

//Get array of key/value arrays
Object.entries(obj); 
// [['name', 'codehood'], ['type', 'channel']]

One thought on “Get Object’s Keys and Values The Easy Way”

Leave a Reply

Your email address will not be published. Required fields are marked *