[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Object/keys [Back]  [Original]

Object.keys() - JavaScript | MDN

This page was translated from English by the community. Learn more and join the MDN Web Docs community.

View in English Always switch to English

Object.keys()

Baseline Widely available

This feature is well established and works across many devices and browser versions. Its been available across browsers since 2015 7.

Object.keys() .

In this article

const object1 = {
  a: "somestring",
  b: 42,
  c: false,
};

console.log(Object.keys(object1));
// Expected output: Array ["a", "b", "c"]

js
Object.keys(obj)

obj

.

.

Object.keys() object . for...in for...in . Object.keys() for...in .

Object.values() . Object.entries() .

Object.keys()

js
//  
const arr = ["a", "b", "c"];
console.log(Object.keys(arr)); // ['0', '1', '2']

//   
const obj = { 0: "a", 1: "b", 2: "c" };
console.log(Object.keys(obj)); // ['0', '1', '2']

//      
const anObj = { 100: "a", 2: "b", 7: "c" };
console.log(Object.keys(anObj)); // ['2', '7', '100']

// getFoo     .
const myObj = Object.create(
  {},
  {
    getFoo: {
      value() {
        return this.foo;
      },
    },
  },
);
myObj.foo = 1;
console.log(Object.keys(myObj)); // ['foo']

, Object.getOwnPropertyNames() .

Object.keys()

. undefined null TypeError . , .

js
//       .
console.log(Object.keys("foo")); // ['0', '1', '2']

// undefined null      .
console.log(Object.keys(100)); // []

: ES5 Object.keys() TypeError .

Specification
ECMAScript 2027 LanguageSpecification
# sec-object.keys


Web Proxy Viewer  |  New URL  |  Original Page