js map find filter some every foreach
js map find filter some every foreach
//===========note===========// map find filter some // true/false 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'} ]; let arr5 = arr4.map(item => item.age +1); // [19, 31, 21] b) arr4.map((item) => { if(item.age > 20){ console.log(item); } }) // {name: "lisi", age: 30, sex: "male"} 2.find a) arr4.find(item => item.name === 'zhangsan'); // {name: "zhangsan", age: 18, sex: "male"} // 无匹配返回undefined 3.filter 返回新数组 filter() 方法创建一个新的数组,新数组中的元素是通过检查指定数组中符合条件的所有元素。 注意: filter() 不会对空数组进行检测。 注意: filter() 不会改变原始数组。 a) arr4.filter(item => item.age > 20); // [{name: "lisi", age: 30, sex: "male"}] b) let arr3 = arr4.filter((item) => { return item.sex !== 'male'; }) // [{name: "xiaohong", age: 20, sex: "female"}]