2018-10-12 15:37:13 -04:00
|
|
|
---
|
|
|
|
title: Generate an Array of All Object Keys with Object.keys()
|
|
|
|
---
|
2019-07-24 00:59:27 -07:00
|
|
|
# Generate an Array of All Object Keys with Object.keys()
|
2018-10-12 15:37:13 -04:00
|
|
|
|
2019-07-24 00:59:27 -07:00
|
|
|
---
|
|
|
|
## Problem Explanation
|
2018-10-12 15:37:13 -04:00
|
|
|
|
|
|
|
- To return the array of users the `Object.keys()` method must take an arguement.
|
|
|
|
- This challenge can be solved using a single line return statement.
|
|
|
|
|
|
|
|
|
2019-07-24 00:59:27 -07:00
|
|
|
---
|
|
|
|
## Solutions
|
2018-10-12 15:37:13 -04:00
|
|
|
|
2019-07-24 00:59:27 -07:00
|
|
|
<details><summary>Solution 1 (Click to Show/Hide)</summary>
|
|
|
|
|
|
|
|
```javascript
|
2018-10-12 15:37:13 -04:00
|
|
|
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) {
|
|
|
|
// change code below this line
|
|
|
|
return Object.keys(obj);
|
|
|
|
// change code above this line
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log(getArrayOfUsers(users));
|
|
|
|
```
|
2019-07-24 00:59:27 -07:00
|
|
|
</details>
|