📜  打印对象键 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:03:39.480000             🧑  作者: Mango

代码示例4
// 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));