Generate an Array of All Object Keys with Object.keys() indexOf Error

Tell us what’s happening:
Whenever i try to run the code, i get the error “Cannot read property ‘indexOf’ of undefined”

Do you know why this won’t work?

Your code so far

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
  Object.keys(obj);
  // change code above this line
}

console.log(getArrayOfUsers(users));

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36.

You don’t have indexOf in your code snippet. Can you paste your full code?

your function doesn’t return anything

function getArrayOfUsers(obj) {
  // change code below this line
   return Object.keys(obj);
  // change code above this line
}
1 Like

That’s worked. Thanks!

Technically all functions return something.

If you don’t explicitly use return then it returns undefined.

function deadFunction(){}
console.log(deadFunction()); // undefined
1 Like