• 小小的js


        //安全登陆不允许iframe嵌入 
        if (window.top !== window.self) {
            window.top.location = window.location;
        }
    

    使用filter过滤参数

        let a = [0];
        a = a.filter(item => {
            return item
        });
    
        console.log(a); //[]  0也会被过滤掉
    
        let b = [0,1,2,undefined];
        b = b.filter(item => {
            return item
        });
    
        console.log(b);//[1, 2]
    

    reduce谜之操作

        const arr = [{id: 1,type: 'A',total: 3}, {id: 2,type: 'B',total: 5}, {id: 3,type: 'E',total: 7}];
        
        const re = arr.reduce((sum,{total})=>{
            return sum + total;
        },0);
    
        const re1 = arr.reduce((str, { id, type,total }) => {
            return str + `id:${id},type:${type},total:${total};`;
        }, '');
    
        const re2 = arr.reduce((res, { id, type, total }) => {
            res[id] = {
                type,
                total
            };
            return res;
        }, {});
    
        const re3 = arr.reduce((res, { id, type, total },index) => {
            res[index] = type;
            return res;
        }, []);
    
    console.log(re); //结果为total的累加
    console.log(re1); //id:1,type:A,total:3;id:2,type:B,total:5;id:3,type:E,total:7;字符串
    console.log(re2); //{1: {type: "A", total: 3}, 2: {…}, 3: {…}}
    console.log(re3); //["A", "B", "E"]
    
    const re3 = arr.reduce((
    第一个参数:累加器累加回调的返回值-res,
    第二个参数:数组中正在处理的元素-{ id, type, total },
    第三个参数可选:当前元素的索引-index,
    第四个参数可选:调用reduce()的数组-array) => {
            res[index] = type;
            return res;
        }, []);
    
  • 相关阅读:
    coredns bug
    Android的Sepolicy
    漫谈fork
    ftrace总结
    Framebuffer
    .net core 5 发送windows10桌面通知
    test_app 测试环境搭建
    GitHub骚操作
    git基于某分支创建新分支
    mysql导入数据load data infile
  • 原文地址:https://www.cnblogs.com/hideonbush/p/9760349.html
Copyright © 2020-2023  润新知