map/filter

박찬미·2021년 11월 9일
0
post-thumbnail

map

const classmates = ["철수", "영희", "훈이"]

classmates.map((el) => el +"어린이")

.map을 해주면 ["철수어린이","영희어린이","훈이어린이"]로 쓸 수 있다.

const classmates = [{name:"철수"}, 
                {name:"영희"},
                {name:"훈이"}]

classmates.map((el) => ({name:`${el.name} +어린이`}))


filter

const classmates = [{name:"철수"}, 
                {name:"영희"},
                {name:"훈이"}]
                
 classmates.filter((el) => (el.age>=11))               

map과 다르게 그대로 냅둘지 없앨지만 정해준다.


map과 filter를 같이 연달아서 사용할 수 있다.

결과가 배열이기 때문에!

profile
우당탕탕

0개의 댓글