DEV Community

Cover image for Get Object's Keys and Values The Easy Way
Islam Sayed
Islam Sayed

Posted on

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.

Mithilfe der Objektmethoden keys (), values ​​() und entries () können Sie ein Array abrufen, das die Schlüssel, Werte und Schlüsselwert-Arrays des Objekts enthält.

Here is the syntax👇

const obj = {
    name: 'codehood',
    type: 'channel'
};

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

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

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

👉Follow me on Twitter: https://twitter.com/islam_sayed8

Oldest comments (0)