22-04-27 JS 데이터2

SOMEmo·2022년 4월 27일
0
post-thumbnail
  1. 구조 분해 할당(Destructuring assignment) = 비구조화 할당
const user = {
  name: 'Heropy',
  age: 85,
  email: 'thesecon@gmail.com'
}

const {name: heropy,age,email,address= 'Korea'} = user
console.log(`${heropy}의 나이는 ${age}세입니다.`)

const fruits = ['Apple', 'Banana', 'Cherry'] 배열
const [a,b,c,d] = fruits
console.log(a,b,c,d) // Apple Banana Cherry undefined

  1. 전개 연산자(rest parameters)
const fruits = ['Apple', 'Banana', 'Cherry']
console.log(...fruits) // Apple, Banana, Cherry

function toObject(a,b,c) {
 return {
  a: a,
  b: b,
  c: c
 }
}
console.log(toObject(...fruits)) // {a:"Apple", b: "Banana", c: "Cherry"}

  1. 얕은 복사와 깊은 복사
const copyUser = Object.assign({}, user) 얕은 복사
const copyUser = {...user} 얕은 복사

깊은 복사

import lodash from 'lodash'
import _ from 'lodash'
const copyUser = _.cloneDeep(user)

0개의 댓글