<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script> <body> <div id="app"> </div> </body> <script> let arr = [1,3,55,8]; // 需求:arr数组中的所有小于5的值翻倍并求和 let count = arr.filter(function(n){ return n < 5; }).map(function(n){ return n*2; }).reduce(function(preValue, n){ return preValue + n; },0); console.log(`和:${count}`); </script> </html>
原文地址:https://www.cnblogs.com/cl94/p/12246887.html
时间: 2024-11-13 14:38:22