js map find filter some every foreach

js map find filter some every foreach

//===========note===========//
map

find
filter

some

every

foreach

1.map
a)
let arr4 = [
            {name: 'zhangsan', age: 18, sex: 'male'},
            {name: 'lisi', age: 30, sex: 'male'},
            {name: 'xiaohong', age: 20, sex: 'female'} 
        ]; 
The let arr5 = arr4.map (Item => + item.age . 1 ); // [. 19, 31 is, 21 is] 
B) 
arr4.map ((Item) => {
     IF (item.age> 20 is ) { 
        the console.log (Item); 
    } 
}) 
// {name: "Lisi", Age: 30, Sex: "MALE"} 

2 .find 
A) 
Item arr4.find ( => item.name, for === ' zhangsan ' ); 

// {name: "zhangsan", Age: 18 is, Sex: "MALE"}
 // no match returns undefined 

. 3 .filter 
returns a new array 
filter () method creates a new array, a new array of array elements are designated by examining in line with the conditions of all the elements.

Note: filter () will not be an empty array detection. 

Note: filter () does not alter the original array. 
A) 
arr4.filter (Item => item.age> 20 is ); 
 // [{name: "Lisi", Age: 30, Sex: "MALE"}] 
B) 
the let ARR3 = arr4.filter ((Item) = > { 
    
    return item.sex ==! ' MALE ' ; 

}) 
// [{name: "Xiaohong", Age: 20 is, Sex: "FEMALE"}]

 

Guess you like

Origin www.cnblogs.com/wn798/p/12016574.html