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

Top comments (0)

Classic DEV Post from 2020:

js visualized

πŸš€βš™οΈ JavaScript Visualized: the JavaScript Engine

As JavaScript devs, we usually don't have to deal with compilers ourselves. However, it's definitely good to know the basics of the JavaScript engine and see how it handles our human-friendly JS code, and turns it into something machines understand! πŸ₯³

Happy coding!