The Web Blinders logo

Programming

How to Get keys of a JavaScript Object

getObjectKeys() will return an array of keys of an object

var obj = {
    name:"John Doe",
    age:23,
    sex:"Male"
};

// returns an array of keys
function getObjectKeys(obj){
    var keys=[];
    Object.entries(obj).forEach(([key])=>{
        // console.log(key);
        keys[]=key;
    });
    return keys;
}

console.log(getObjectKeys(obj));

// (3) ["name", "age", "sex"]

ALTERNATE TITLES

Get keys of Javascript Object

Get values of Javascript object

get keys and values of a javascript object

Object.entries() example

Need developers ?

if so, send a message.

thewebblinders@gmail.com

More Programming from our blog

SEARCH FOR ARTICLES