💡 자바스크립트의 객체 메서드를 알아보자.
Object.keys()key)을 배열로 반환한다.const person = { name: "ttining", age: 100 };
const keys = Object.keys(person);
console.log(keys); // ["name", "age"]Object.values()value)을 배열로 반환한다.const person = { name: "ttining", age: 100 };
const values = Object.values(person);
console.log(values); // ["ttining", 100]Object.entries()[key, value] 쌍을 배열로 반환한다.const person = { name: "ttining", age: 100 };
const entries = Object.entries(person);
console.log(entries); // [["name", "ttining"], ["age", 100]]Object.assign()const person = { name: "ttining", age: 100 };
const updatedPerson = Object.assign({}, person, { age: 800 });
console.log(updatedPerson); // { name: "ttining", age: 800 }Object.freeze()const person = { name: "ttining", age: 100 };
Object.freeze(person);
person.age = 20; // 변경되지 않음
console.log(person.age); // 100Object.getOwnPropertyNames()Object.keys()와 비슷하지만, 상속된 속성은 제외하고 객체 고유의 속성만 반환한다.const person = { name: "ttining", age: 100 };
const propertyNames = Object.getOwnPropertyNames(person);
console.log(propertyNames); // ["name", "age"]Object.getOwnPropertyDescriptor()const person = { name: "ttining", age: 100 };
const descriptor = Object.getOwnPropertyDescriptor(person, "name");
console.log(descriptor);
// { value: "ttining", writable: true, enumerable: true, configurable: true }hasOwnProperty()const person = { name: "ttining", age: 100 };
console.log(person.hasOwnProperty("name")); // true
console.log(person.hasOwnProperty("address")); // false