배열 메서드
- map() - 배열의 각 요소를 반환하여 새 배열 반환
const doubled = numbers.map(num => num * 2)
- filter() - 조건에 맞는 요소만 골라내어 새 배열 반환
const evens = numbers.filter(num => num % 2 === 0)
- reduce() - 배열의 요소를 줄여서 하나의 값으로 만듦
const sum = numbers.reduce((acc, curr) => acc + curr, 0)
- sort() - 배열을 정렬
numbers.sort((a, b) => a - b)
numbers.sort((a, b) => b - a)
- forEach() - 배열의 각 요소에 대해 함수 실행
numbers.forEach(num => console.log(num))
- find() - 조건에 맞는 첫 번째 요소 반환
const found = numbers.find(num => num > 10)
- some() - 배열에 조건을 만족하는 요소가 하나라도 있는지 확인
const hasEven = numbers.some(num => num % 2 === 0)
- every() - 배열에 모든 요소가 조건을 만족하는지 확인
const allPositive = numbers.every(num => num > 0)
- push(), pop() - 배열 끝에 요소 추가/제거
array.push(5)
const last = array.pop()
- shift(), unshift() - 배열 앞에서 요소 제거/추가
array.unshift(1)
const first = array.shift()
- slice() - 배열의 일부분 추출
const subArray = array.slice(2, 5)
- concat() - 배열들을 합쳐 새 배열 생성
const combined = array1.concat(arrat2)
문자열 메서드
- split() - 문자열을 구분자로 나누어 배열로 변환
const parts = str.split(',')
- join() - 배열을 문자열로 합치기
const joined = array.join('-')
- substring() - 문자열의 일부분 추출
const part = str.substring(2, 5)
- replace() - 문자열의 일부 교체
const newStr = str.replace('old', 'new')
- toLowerCase(), toUpperCase() - 소문자/대문자 변환
const lower = str.toLowerCase
수학 메서드
- Math.max(), Math.min() - 최댓값/최솟값 찾기
const max = Math.max(...numbers)
- Math.floor(), Math.ceil(), Math.round() - 정수로 반올림/올림/내림
const rounded = Math.floor(3.7)
- Math.abs() - 절댓값
const absolute = Math.abs(-5)
객체 메서드
- Object.keys(), Object.values() - 객체의 키/값 배열 반환
const keys = Object.keys(obj)
const values = Object.values(obj)
- Object.entries() - 객체의
[키,값] 쌍 배열 반환
const entries = Object.entries(obj)
집합/맵 자료구조
- Set - 중복 없는 집합
const uniqueValues = new Set(array)
const uniqueArray = [...uniqueValues]
- Map - 키-값 쌍을 저장하는 컬렉션
const frequency = new Map()
for (const num of array) {
frequency.set(num, (frequency.get(num) || 0) + 1)
}