* chore(i18n,curriculum): update translations * chore: Italian to italian Co-authored-by: Nicholas Carrigan <nhcarrigan@gmail.com>
2.1 KiB
2.1 KiB
id, title, challengeType, forumTopicId, dashedName
id | title | challengeType | forumTopicId | dashedName |
---|---|---|---|---|
587d7b7d367417b2b2512b1e | Creare l'array delle proprietà con Object.keys() | 1 | 301160 | generate-an-array-of-all-object-keys-with-object-keys |
--description--
Possiamo anche generare un array che contiene tutte le chiavi memorizzate in un oggetto, utilizzando il metodo Object.keys()
e passandogli un oggetto come argomento. Questo restituirà un array con stringhe che rappresentano ogni proprietà nell'oggetto. Di nuovo, non ci sarà alcun ordine specifico per gli elementi nell'array.
--instructions--
Termina la scrittura della funzione getArrayOfUsers
in modo che restituisca un array contenente tutte le proprietà nell'oggetto che riceve come argomento.
--hints--
L'oggetto users
dovrebbe contenere solo le chiavi Alan
, Jeff
, Sarah
e Ryan
assert(
'Alan' in users &&
'Jeff' in users &&
'Sarah' in users &&
'Ryan' in users &&
Object.keys(users).length === 4
);
La funzione getArrayOfUsers
dovrebbe restituire un array che contiene tutte le chiavi nell'oggetto users
assert(
(function () {
users.Sam = {};
users.Lewis = {};
let R = getArrayOfUsers(users);
return (
R.indexOf('Alan') !== -1 &&
R.indexOf('Jeff') !== -1 &&
R.indexOf('Sarah') !== -1 &&
R.indexOf('Ryan') !== -1 &&
R.indexOf('Sam') !== -1 &&
R.indexOf('Lewis') !== -1
);
})() === true
);
--seed--
--seed-contents--
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) {
// Only change code below this line
// Only change code above this line
}
console.log(getArrayOfUsers(users));
--solutions--
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);
}
console.log(getArrayOfUsers(users));