javascript(2)
-
substring substr slice
헷갈리는 메서드를 한번 정리 해보았다. 1. substring substr slice 공통점 모두 최초 데이터를 변환 시키지 않는다. 2. slice(startIndex,endIndex) start 부터 end 인덱스 구간을 반환한다. end 는 생략 가능 : end 가 생략되면 start 부터 끝까지 반환한다. start 가 음수일 경우 끝에서 부터 인덱스가 시작된다. const data = "abc bcd" data.slice(1) //"bc bcd" data.slice(1,1) //"" data.slice(1,2) //"b" data.slice(-1) //"d" data.slice(-2) //"cd" data.slice(-2,-1) //"c" 3. substr(start,count) start 는 ..
2021.08.21 -
Set
MDN 문서 value 값이 중복 되면 자동으로 하나만 남고 전부 삭제된다. delete, has, add 같은 빠르고 간편한 메서드가 제공된다. 빠르다. 중복 없앨때 편하다. 만약 set을 안쓴다면 중복 여부를 체크 할때? const array = [1,2,3,4,1] const newArray = [] array.forEach((item,index)=>{ if(!(array.indexOf(item)!==index)){ newArray.push(item) } }) 간편하게 set을 사용한다면? const newArray = new Set(array) set 으로 교집합 차집합 기능 도 가능하다. const intersection = new Set([...set1].filter(x => set2.has(..
2021.08.16