美文网首页
js 高级函数的使用

js 高级函数的使用

作者: Rascar | 来源:发表于2020-04-30 17:22 被阅读0次
    let arr = [1, 2, 40, 2, 02, 3, 2, 4, 3, 4, 7, 894564, 4862, 46, 10]
                /**实例1*/
                let count = arr.filter(item => { //先筛选
                    return item > 2
                }).map((n) => { //在每个数都  * 5
                    return n * 5
                }).reduce((preve, n) => { //在计算
                    return preve + n
                }, 0)
                console.log(count)
                
                
                /**实例2*/
                
                let count = arr.filter(item=>item>5).map(item=>item * 5).reduce((preve,item)=> preve + item)
                console.log(count)
    
    
                let inof = arr.findIndex(item => item == 40) //-1 为不存在   其他为存在  //还可以找下标
                // console.log(inof)
                if (inof != -1) {
                    console.log("11")
                }

    相关文章

      网友评论

          本文标题:js 高级函数的使用

          本文链接:https://www.haomeiwen.com/subject/kbrtghtx.html