xxxxxxxxxx
const myObj = {
firstName: 'John',
lastName: 'Duo',
address: '1270.0.0.1'
}
const keys = Object.keys(myObj); // firstName, lastName, address
const values = Object.values(myObj); // John, Duo, 127.0.0.1
xxxxxxxxxx
var foo = {
'alpha': 'puffin',
'beta': 'beagle'
};
var keys = Object.keys(foo);
console.log(keys) // ['alpha', 'beta']
// (or maybe some other order, keys are unordered).
xxxxxxxxxx
const object1 = {
a: 'somestring',
b: 42,
c: false
};
console.log(Object.keys(object1));
// expected output: Array ["a", "b", "c"]
xxxxxxxxxx
const keysAndValues = (obj) => [Object.keys(obj), Object.values(obj)];
keysAndValues({a: 1, b: 2, c: 3});
//➞ [["a", "b", "c"], [1, 2, 3]]
keysAndValues({a: "Dell", b: "Microsoft", c: "Google"}));
//➞ [["a", "b", "c"], ["Dell", "Microsoft", "Google"]]
keysAndValues({key1: true, key2: false, key3: undefined});
// ➞ [["key1", "key2", "key3"], [true, false, undefined]]
xxxxxxxxxx
var obj = { "a" : 1, "b" : 2, "c" : 3};
alert(Object.keys(obj));
// will output ["a", "b", "c"]
xxxxxxxxxx
const myObject = {
key1: 'value1',
key2: 'value2',
key3: 'value3'
};
const keys = Object.keys(myObject);
console.log(keys); // Output: ["key1", "key2", "key3"]
xxxxxxxxxx
const person = {
key: "value",
first_name: "John",
last_name: "Doe"
};
Object.keys(person);
Output: ['key', 'first_name', 'last_name']
xxxxxxxxxx
const object = {
name: "John",
age: 30,
gender: "male"
};
const keys = Object.keys(object);
console.log(keys);
xxxxxxxxxx
obj={
name:"akash",
age:23
}
keysval=Object.keys(obj)
console.log(keysval)