Ключи объекта JavaScript
const object1 = {
a: 'somestring',
b: 42,
c: false
};
console.log(Object.keys(object1));
// expected output: Array ["a", "b", "c"]
Kaotik
const object1 = {
a: 'somestring',
b: 42,
c: false
};
console.log(Object.keys(object1));
// expected output: Array ["a", "b", "c"]
// Object.key()
let users = {
Alan: {
age: 27,
online: false,
},
Jeff: {
age: 32,
online: true,
},
Sarah: {
age: 48,
online: false,
},
Ryan: {
age: 19,
online: true,
},
};
function getArrayOfUsers(obj) {
return Object.keys(obj); // [ 'Alan', 'Jeff', 'Sarah', 'Ryan' ]
}
console.log(getArrayOfUsers(users));
const object1 = {
a: 'somestring',
b: 42,
c: false
};
console.log(Object.keys(object1));