map() , filter() 및 reduce() 메서드에 대한 간단한 터치
                                            
                                                
                                                
                                                
                                                
                                                
                                                 9203 단어  reactprogrammingwebdevjavascript
                    
지도:
map() 메서드는 기존 배열에서 새 배열을 만들고 첫 번째 배열의 각 요소에 함수를 적용합니다.
예를 들어
 const numbers = [1, 2, 3, 4];
const doubled = numbers.map(item => item * 2);
console.log(doubled); // [2, 4, 6, 8]
 필터:
filter() 메서드는 조건문을 기반으로 값을 반환합니다. 배열의 각 요소에 대한 조건을 확인하고 조건이 true이면 반환하지 않으면 반환합니다.
예를 들어
 const numbers = [4, 7, 12, 3];
const evens = numbers.filter(item => item % 2 === 0);
console.log(evens); // [4, 12]
 const students = [
  { name: 'abc', attendance: 96 },
  { name: 'mno', attendance: 60 },
  { name: 'def', attendance: 89 },
  { name: 'jkl', attendance: 65 },
  { name: 'xyz', attendance: 40 }
];
const eligibleStudent = students.filter(student => student.attendance >= 75);
return eligibleStudent; // [ { name: 'abc', grade: 96 }, { name: 'def', grade: 89}]
 줄이다:
reduce() 메서드는 배열의 각 요소에 대해 제공된 함수를 실행하여 배열을 단일 값으로 줄입니다.
통사론:
 array.reduce(function(total, currentValue, currentIndex, arr), initialValue)
Total(초기값 또는 이전에 반환된 함수 값) 및 currentValue(현재 요소의 값)는 필수 매개변수입니다. InitialValue는 선택 사항이며 배열의 초기 값을 설정합니다. initialValue가 제공되지 않으면 배열의 첫 번째 요소가 초기값으로 사용됩니다. initialValue가 없는 빈 배열에서 reduce()를 호출하면 TypeError가 발생합니다.
예를 들어
 const euros = [29.76, 41.85, 46.5];
const sum = euros.reduce((total, amount) => total + amount); 
console.log(sum)  // 118.11
 var pilots = [
  {
    id: 10,
    name: "Poe Dameron",
    years: 14,
  },
  {
    id: 2,
    name: "Temmin 'Snap' Wexley",
    years: 30,
  },
  {
    id: 41,
    name: "Tallissan Lintra",
    years: 16,
  },
  {
    id: 99,
    name: "Ello Asty",
    years: 22,
  }
];
const totalYears = pilots.reduce((acc, pilot) => acc + pilot.years, 0); 
console.log(totalYears) //82
그것이 이 주제에 대한 것입니다. 배운 것이 있으면 개발자 친구와 공유하십시오. 개발 및 기술 항목에 대한 매일 트윗을 위해 저를 팔로우하세요. 즐거운 코딩👨💻❤ .
                
                    
        
    
    
    
    
    
                
                
                
                
                    
                        
                            
                            
                            Reference
                            
                            이 문제에 관하여(map() , filter() 및 reduce() 메서드에 대한 간단한 터치), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
                                
                                https://dev.to/arifimran5/brief-touch-on-map-filter-and-reduce-methods-5g41
                            
                            
                            
                                텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
                            
                            
                                
                                
                                 우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)
                                
                                
                                우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)
                            
                            
                        
                    
                
                
                
            
const numbers = [1, 2, 3, 4];
const doubled = numbers.map(item => item * 2);
console.log(doubled); // [2, 4, 6, 8]
filter() 메서드는 조건문을 기반으로 값을 반환합니다. 배열의 각 요소에 대한 조건을 확인하고 조건이 true이면 반환하지 않으면 반환합니다.예를 들어
const numbers = [4, 7, 12, 3];
const evens = numbers.filter(item => item % 2 === 0);
console.log(evens); // [4, 12]
const students = [
  { name: 'abc', attendance: 96 },
  { name: 'mno', attendance: 60 },
  { name: 'def', attendance: 89 },
  { name: 'jkl', attendance: 65 },
  { name: 'xyz', attendance: 40 }
];
const eligibleStudent = students.filter(student => student.attendance >= 75);
return eligibleStudent; // [ { name: 'abc', grade: 96 }, { name: 'def', grade: 89}]
줄이다:
reduce() 메서드는 배열의 각 요소에 대해 제공된 함수를 실행하여 배열을 단일 값으로 줄입니다.
통사론:
 array.reduce(function(total, currentValue, currentIndex, arr), initialValue)
Total(초기값 또는 이전에 반환된 함수 값) 및 currentValue(현재 요소의 값)는 필수 매개변수입니다. InitialValue는 선택 사항이며 배열의 초기 값을 설정합니다. initialValue가 제공되지 않으면 배열의 첫 번째 요소가 초기값으로 사용됩니다. initialValue가 없는 빈 배열에서 reduce()를 호출하면 TypeError가 발생합니다.
예를 들어
 const euros = [29.76, 41.85, 46.5];
const sum = euros.reduce((total, amount) => total + amount); 
console.log(sum)  // 118.11
 var pilots = [
  {
    id: 10,
    name: "Poe Dameron",
    years: 14,
  },
  {
    id: 2,
    name: "Temmin 'Snap' Wexley",
    years: 30,
  },
  {
    id: 41,
    name: "Tallissan Lintra",
    years: 16,
  },
  {
    id: 99,
    name: "Ello Asty",
    years: 22,
  }
];
const totalYears = pilots.reduce((acc, pilot) => acc + pilot.years, 0); 
console.log(totalYears) //82
그것이 이 주제에 대한 것입니다. 배운 것이 있으면 개발자 친구와 공유하십시오. 개발 및 기술 항목에 대한 매일 트윗을 위해 저를 팔로우하세요. 즐거운 코딩👨💻❤ .
                
                    
        
    
    
    
    
    
                
                
                
                
                    
                        
                            
                            
                            Reference
                            
                            이 문제에 관하여(map() , filter() 및 reduce() 메서드에 대한 간단한 터치), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
                                
                                https://dev.to/arifimran5/brief-touch-on-map-filter-and-reduce-methods-5g41
                            
                            
                            
                                텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
                            
                            
                                
                                
                                 우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)
                                
                                
                                우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)
                            
                            
                        
                    
                
                
                
            
array.reduce(function(total, currentValue, currentIndex, arr), initialValue)
const euros = [29.76, 41.85, 46.5];
const sum = euros.reduce((total, amount) => total + amount); 
console.log(sum)  // 118.11
var pilots = [
  {
    id: 10,
    name: "Poe Dameron",
    years: 14,
  },
  {
    id: 2,
    name: "Temmin 'Snap' Wexley",
    years: 30,
  },
  {
    id: 41,
    name: "Tallissan Lintra",
    years: 16,
  },
  {
    id: 99,
    name: "Ello Asty",
    years: 22,
  }
];
const totalYears = pilots.reduce((acc, pilot) => acc + pilot.years, 0); 
console.log(totalYears) //82
Reference
이 문제에 관하여(map() , filter() 및 reduce() 메서드에 대한 간단한 터치), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://dev.to/arifimran5/brief-touch-on-map-filter-and-reduce-methods-5g41텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
                                
                                
                                
                                
                                
                                우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)