您当前的位置: 首页 > 

暂无认证

  • 2浏览

    0关注

    92582博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

js中数组高级API下

发布时间:2020-09-21 23:17:56 ,浏览量:2

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <body> <script type="text/javascript"> let arr = [1, 2, 3, 4, 5]; // 1.数组的filter方法: // 将满足条件的元素添加到一个新的数组中 let a=arr.filter(function(a,b,c) {//currentValue, currentIndex, currentArray if(a%2===0) { return true; } }); console.log(a); // 2.数组的map方法: // 将满足条件的元素映射到一个新的数组中 let newArray = arr.map(function (currentValue, currentIndex, currentArray) { // console.log(currentValue, currentIndex, currentArray); if(currentValue % 2 === 0){ return currentValue; } }); console.log(newArray); // [undefined, 2, undefined, 4, undefined] </script> </body> </html> 

方法的实现:

关注
打赏
1653961664
查看更多评论
立即登录/注册

微信扫码登录

0.0738s