DEV Community

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

Posted on

2 1

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)

SurveyJS custom survey software

JavaScript Form Builder UI Component

Generate dynamic JSON-driven forms directly in your JavaScript app (Angular, React, Vue.js, jQuery) with a fully customizable drag-and-drop form builder. Easily integrate with any backend system and retain full ownership over your data, with no user or form submission limits.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay