Object.keys()
: 주어진 객체의 속성 이름들을 일반적인 반복문과 동일한 순서로 순회되는 열거할 수 있는 배열로 반환
// 사용법
Object.keys(obj)
const object1 = {
a: 'somestring',
b: 42,
c: false,
};
console.log(Object.keys(object1));
// Expected output: Array ["a", "b", "c"]
Object.values()
: 객체의 모든 값들을 배열 형태로 반환하기 위해 사용
// 사용법
Object.values(obj);
const user = {
name: 'Alice',
age: 30,
job: 'Engineer'
};
const values = Object.values(user);
console.log(values); // ['Alice', 30, 'Engineer']
Object.assign()
: 출처 객체들의 모든 열거 가능한 자체 속성을 복사해 대상 객체에 붙여넣은 후 대상 객체를 반환
// 사용법
Object.assign(target, ...sources);
const target = { a: 1, b: 2 };
const source = { b: 4, c: 5 };
const returnedTarget = Object.assign(target, source);
console.log(target);
// Expected output: Object { a: 1, b: 4, c: 5 }
console.log(returnedTarget === target);
// Expected output: true
출처
https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Object/Object
'JAVASCRIPT' 카테고리의 다른 글
reduce() 정리 (0) | 2024.08.14 |
---|---|
[Array] 배열 객체의 메소드 ' .findIndex() '와 ' .indexOf '의 차이 (0) | 2024.06.11 |
[Array] 배열 객체의 메소드 ' .find() '와 ' .filter() '의 차이 (0) | 2024.06.11 |
자바스크립트를 이용한 달력만들기 (0) | 2022.10.04 |
댓글