Array.from()
정의 Array.from() 메서드는 유사 배열 객체나 반복 가능한 객체를 얕게 복사해 새로운 Array 객체를 만듭니다. console.log(Array.from('sangyun')); // output : ["s","a","n","g","y","u","n"] console.log(Array.from([3,4,5],x=>x*x)); // output : [9,16,25] 구문 Array.from(arrayLike[,mapFn[,thisArg]]) 매개변수 arrayLike 배열로 변환하고자 하는 유사 배열 객체나 반복 가능한 객체 mapFn (Optional) 배열의 모든 요소에 대해 호출할 맵핑 함수 thisArg (Optional) mapFn 실행 시에 this로 사용할 값 설명 Array.from..
2021. 7. 16.
Array Method : Splice vs Slice
Splice() 기존 요소를 제거하거나 교체하고 새 요소를 추가하여 배열의 내용을 변경해준다. 매개변수 splice(start, deleteCount, item1, item2, itemN) 반환값 삭제된 요소를 포함하는 배열 한 요소만 제거되면 한 요소의 배열이 반환 요소가 제거되지 않으면 빈 배열이 반환 start : 배열 변경을 시작할 인덱스 deleteCount : 제거할 배열의 요소 수를 나타내는 정수 item1,item2,... : 배열에 추가할 요소 let number = [1,2,3,4,5,6]; let remove = number.splice(1,0,3); //number = [3,1,2,3,4,5,6] //remove = [] 추가적 예시 : https://developer.mozilla..
2021. 7. 15.
2021/07/14 - CodeReview
Project : 달력과 연동되는 가계부 만들기 / BCSD team project (1) CustomHook을 바로 JSX내부에서 사용하지말고, 함수 컴포넌트에 선언을 하고, 사용을 하자 +{useGiveSum('INCOME',month,year)} {useGiveSum('EXPEDITURE',month,year)} useGiveSum이라는 customHook은 type = {수입,지출}에 따라 수입의 총합, 지출의 총합을 return해준다. 위와같은 방식으로 불러온 customHook을 바로 사용해주는 것보다 변수를 새로 하나 선언을 해서 그 변수에 useGiveSum에서 return되는 값을 재사용하는 식으로 수정을 하자 incomeSum = useGiveSum('INCOME',month,year)..
2021. 7. 14.
CustomHook만들어 사용하기
const MONTHS = ['Jan','Feb','Mar','Apr','May','Jun','July','Aug','Sep','Oct','Nov','Dec']; const sumIncome = (lists,month,year) => { const income = lists .filter((list)=>list.month===month&&list.type==='INCOME'&&Number(list.year)===year) .map((list)=>{ return Number(list.amount); }) .reduce((acc,cur)=>{ return acc+cur; },0); return transformation(income); }//월별 수입 합계를 구해주는 함수 const sumExpediture..
2021. 7. 14.