JavaScript Object.getOwnPropertyNames()

정의와 사용법

Object.getOwnPropertyNames() 메서드는 객체의 모든 속성 이름을 포함한 배열을 반환합니다.

Object.getOwnPropertyNames() 메서드는 원본 객체를 변경하지 않습니다.

관련 메서드:

Object.defineProperty() 속성을 추가하거나 수정합니다.

Object.defineProperties() 여러 속성을 추가하거나 수정합니다.

Object.getOwnPropertyNames() 객체의 모든 속성 이름을 반환합니다.

Object.getOwnPropertyDescriptor() 속성의 설명자를 반환합니다.

Object.getOwnPropertyDescriptors() 객체의 모든 속성의 설명자를 반환합니다.

实例

// 객체를 생성하다
const person = {
  firstName: "Bill",
  lastName: "Gates",
  age: 50,
  eyeColor: "blue"
};
// 모든 속성 이름을 가져오기
let props = Object.getOwnPropertyNames(person);

직접 실습해보세요

문법

Object.getOwnPropertyNames(object)

파라미터

파라미터 설명
object 필수. 대상 객체.

반환 값

타입 설명
Array 객체의 모든 속성 이름을 포함한 배열.

브라우저 지원

Object.getOwnPropertyNames() ECMAScript5 (ES5)의 특성입니다.

2013년 7월부터 모든 현대 브라우저는 완전히 ES5(JavaScript 2009)를 지원합니다:

Chrome Edge Firefox Safari Opera
Chrome 23 IE/Edge 11 Firefox 21 Safari 6 Opera 15
2012년 9월 2012년 9월 2013년 4월 2012년 7월 2013년 7월