Swapping and Skipping

Jeong Ha Seung·2021년 11월 29일

ES6

목록 보기
4/9
let mon = "Sat";
let sat = "Mon"; //누군가 이렇게 잘못 입력했다고 하면

[sat, mon] = [mon, sat]; //이처럼 swapping 해주면

console.log(mon, sat); //Mon Sat 올바르게 나온다.

const days = ["mon", "tue", "wed", "thu", "fri"]; //이 같은 5개 element가 들어있는 array가 있을 때
const [, , , thu, fri] = days; //마지막 2개만 가져오고 싶다면 나머지는 ,로 처리하면 된다.

console.log(thu, fri); //thu fri
profile
블로그 이전했습니다. https://morethan-haseung-log.vercel.app

0개의 댓글