JavaScript/JavaScript
JS 자세히 알아보기 (객체 데이터)
IT Blue
2021. 6. 6. 03:58
객체 데이터
const userAge = {
// key: value
name: 'Yoo',
age: 27
}
const userEmail = {
name: 'Yoo',
email: 'ITBlue@tistory.com'
}
// Object.assign()
// 열거할 수 있는 하나 이상의 출처 객체로부터 대상 객체로 속성을 복사할 때 사용
// 정적 메소드
const target = Object.assign(userAge, userEmail)
// {name: "Yoo", age: 27, email: 'ITBlue@tistory.com'}
console.log(target)
// {name: "Yoo", age: 27, email: 'ITBlue@tistory.com'}
console.log(userAge)
// true
console.log(target === userAge)
const a = { k: 123}
const b = { k: 123}
// false
console.log(a === b)
const user = {
name: 'Yoo',
age: 27,
email: 'ITBlue@tistory.com'
}
// 배열의 각 인덱스를 키 값으로 가지는 새로운 Array Iterator 객체를 반환
const keys = Object.keys(user)
// ["name", "age", "email"]
console.log(keys)
// ITBlue@tistory.com
console.log(user['email'])
const values = keys.map(key => user[key])
// ["Yoo", 27, "ITBlue@tistory.com"]
console.log(values)
참조
https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Object
Object - JavaScript | MDN
Object 생성자는 객체 래퍼(wrapper)를 생성합니다.
developer.mozilla.org