입력:22/07/29수정:24/02/04
Typescript 문법을 위한 Sugar Syntax
Conditional property
const person = {
id: 'abx',
...(isVliad && { isActive: true }),
...((age >= 10 || isValid) && { card: true }),
}
property 존재여부 체크
const person = { id: 'abc' }
console.log('id' in person)
desturctive property
const productData = { id: '12', name: 'laptop' }
const { id: helloworld } = productData
console.log(helloworld, 'hello world is')
key,value interator
const data = {id:1, name: 'laptop', isSale:true}
Object.entries(data).forEach(([key,value])=>{
console.log(`${key} and ${value}`)
})
optional (함수포함)
const data = {id:1, name: 'laptop', isSale:true}
console.log(data?.id)
console.log(data?.hello)
data?.nameDiplay?.()
filter primary type
const fruitList = ['apple', null , 'mango']
const filteredFruit = fruitList.filter(Boolean)
const isANyFruit = fruitList.some(Boolean)
uniq
const fruitList = ['apple', 'mango', 'apple']
const uniqFruit = [...new Set(fruitList)]
type check
Array.isArray()
?? 또는 ||
??는 앞에꺼 먼저
||는 뒤에꺼 먼저
Array Utility
[].some
[].every
소스: 11 Useful Modern JavaScript Tips
토픽: Typescript
카테고리: 스크랩/아티클