[JS] 배열 함수(map, forEach, filter, some, every, find, findIndex)

Subin Ryu·2024년 9월 24일
0
post-thumbnail

배열 함수

배열의 모든 요소를 순회할 때 사용하는 콜백함수

map

  • map((item,index)=>{return }): return값을 출력해서 새로운 배열을 반환하는 콜백함수

forEach

  • forEach((item,index)=>{}): return 값이 없는 콜백함수

filter

  • filter((item)=>{return (조건)}): true로 떨어지는 조건에 부합하는 것만 배열로 반환
  • 조건들(startWith())

some

  • some((item)=>{return (조건)}): 조건에 따라 truefalse 반환
  • 하나라도 조건에 부합하면 true

every

  • every((item)=>{return (조건)}): 조건에 따라 truefalse 반환
  • 배열의 모든 요소가 조건에 부합하면 true

find

  • find((item)=>{return (조건)}): true로 떨어지는 조건에 부합하는 것만 단일로 반환
  • 처음 찾은 하나만 반환
  • 배열형태 아님

findIndex

  • findIndex((item)=>{return (조건)}): true로 떨어지는 조건에 부합하는 것만 단일로 인덱스로 반환
  • 처음 찾은 하나만 반환
  • 배열형태 아님
profile
개발블로그입니다.

0개의 댓글