xxxxxxxxxx
Object.keys(whateverYourObjectIsCalled)
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 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
const object1 = {
a: 'somestring',
b: 42,
c: false
};
console.log(Object.keys(object1));
// expected output: Array ["a", "b", "c"]
xxxxxxxxxx
var obj = { "a" : 1, "b" : 2, "c" : 3};
alert(Object.keys(obj));
// will output ["a", "b", "c"]
xxxxxxxxxx
const person = {
key: "value",
first_name: "John",
last_name: "Doe"
};
Object.keys(person);
Output: ['key', 'first_name', 'last_name']
xxxxxxxxxx
const myObject = {
key1: 'value1',
key2: 'value2',
key3: 'value3'
};
const keys = Object.keys(myObject);
console.log(keys); // Output: ["key1", "key2", "key3"]
xxxxxxxxxx
const object = {
name: "John",
age: 30,
gender: "male"
};
const keys = Object.keys(object);
console.log(keys);
xxxxxxxxxx
// Sample object
const obj = {
key1: "value1",
key2: "value2",
key3: "value3"
};
// Retrieve keys of the object using Object.keys method
const keys = Object.keys(obj);
// Print the keys
console.log(keys);
xxxxxxxxxx
var myObj = {no:'u',my:'sql'}
var keys = Object.keys(myObj);//returnes the array ['no','my'];
xxxxxxxxxx
const object = { a: 5, b: 6, c: 7 };
const picked = (({ a, c }) => ({ a, c }))(object);
console.log(picked); // { a: 5, c: 7 }