filter, forEach ,map 비교!
                                            
                                                
                                                
                                                
                                                
                                                
                                                 4928 단어  JavaScriptJavaScript
                    
오늘은 javaScript의 filter,map method에 대해서 알아보자!🦋
1. filter()
간단히 말하면
- 조건을 줬을때 해당하는 조건의 요소들을 새로운 배열로 리턴해주는 메소드이다!
 - 원본배열에 영향을 주지 않는다.(새로운 배열을 만든다.)
 
const words = ['a','bb','ccc','dddd','eeeeee'];
const result = words.filter(word=> word.length>3);
console.log(result);
console.log(words);
//  ["dddd", "eeeeee"]
//  ["a", "bb", "ccc", "dddd", "eeeeee"]
2. forEach()
- 각각의 배열 요소를 꺼내준다.
 - 원본배열에 영향을 주지 않는다.
 
const array = ['a','b','c'];
array.forEach(item => console.log(item));
//a
//b
//c
3. map()
- 원본배열에 영향을 주지 않는다.(새로운 배열을 만든다.)
 - 메서드의 인수로 함수를 넘긴다.
 - 요소를 일괄적으로 변경한다.
 
const testarray = [1,2,3,4];
const testmap = testarray.map(item=>item*3);
console.log(testmap);
console.log(testarray);
// [3,6,9,12];
// [1,2,3,4];
오늘은 여기까지! 크크><ㅋ
출처: https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Array/filter
(mdn love..🥰)
Author And Source
이 문제에 관하여(filter, forEach ,map 비교!), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@lemon-ginger/filter-forEach-map-비교저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
                                
                                
                                
                                
                                
                                우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)