DevOps BootCamp/Java script 문법 정리
Array.isArray, filter, map, reduce 문법
cloudmaster
2023. 5. 31. 09:02
Array.isArray(인자)
-> 배열인지 아닌지 확인
객체 안에 데이터는 {객체.키}로 접근 가능
Object.keys() -> 객체를 배열로 변환
기술 부채: 기술적인 문제를 해결하지 않고 미루는 것
obj.hasOwnProperty -> 객체의 키를 찾는 함수
obj.filter((element) => 조건) -> 원하는 조건에 성분만 추출
map() 메서드는 배열 내의 모든 요소 각각에 대하여 주어진 함수를 호출한 결과를 모아 새로운 배열을 반환
ex) arr.map(function(element) {
적용할 내용
});
obj[property].map(element => square(element));
-> obj[property]가 배열일 경우 각 요소마다 square 함수 적용
const sum = arr.reduce((accumulator, currentValue) => accumulator + currentValue);
accumulator : 누적값
currentValue : 현재값