map (映射)
1 2 3
| var arrList =[1,2,3,4]; console.log(arrList.map(item => item * item ))
|
filter (过滤筛选)
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| var users = [ {name: "张含韵", "email": "zhang@email.com"}, {name: "江一燕", "email": "jiang@email.com"}, {name: "李小璐", "email": "li@email.com"} ];
var emailList=users.map(userItem => userItem.email); console.log(emailList.join(','))
var liEmail=emailList.filter(email=>/^li/g.test(email)) console.log(liEmail.join(''))
|
find
1 2
| [1, 4, -5, 10].find((n) => n < 0)
|
findIndex
1 2 3 4 5 6 7 8
| [1, 4, -5, 10].findIndex((value,index,arr) => console.log(value,index,arr));
|
some (至少一个符合)
1 2 3 4 5 6 7 8 9 10
| var numbers = [2, 4, 10, 6, 8]; var a = numbers.some((item,index)=>{ if(item%3===0){ return true; }else{ return false; } }); console.log(a)
|
every (任何一个都需要符合)
1 2 3 4 5 6 7 8 9 10
| var numbers = [2, 4, 10, 4, 8]; var a = numbers.every((item,index)=>{ if(item%2===0){ return true; }else{ return false; } }); console.log(a)
|