[코테준비] 자바스크립트 코드트릭

SeHoony·2022년 8월 16일
0

코테준비

목록 보기
1/27

1. 자바스크립트 코드 트릭

1-1. 구조분해할당 SWAP

let a = 1, let b = 2
[a,b] = [b,a]

1-2. 배열 생성

const array = Array.from(new Array(5), (_,k) => k+5)

1-3. 중복 제거

const nums = [1,1,1,1,1,2]
1. const new1 = Array.from(new Set(nums))
2. const new2 = [...new Set(nums)]

1-4. Spread를 통한 객체 병합

const a = {name : 'sehoon'}
const b = {height : 180}

const c = {...a, ...b}
console.log(c) => {name : "sehoon", height:180}

1-5. 구조분해할당으로 꺼내쓰기

const {name, height} = c

1-6. 객체의 키 동적 생성

const nameKey = "name"
const emailKey = "email"

const person = {
	[nameKey] : "kang-sehoon",
  	[emailKey] : "gsh723@naver.com"
}

1-7. !! 연산자

값을 boolean 값으로 변경할 수 있다.

profile
두 발로 매일 정진하는 두발자, 강세훈입니다. 저는 '두 발'이라는 이 단어를 참 좋아합니다. 이 말이 주는 건강, 정직 그리고 성실의 느낌이 제가 주는 분위기가 되었으면 좋겠습니다.

0개의 댓글