JavaScript对象数据过滤、修改


 

       let array1 = [];
            let array2 = [];
            array.forEach(e => {
                if (e.salary >= 3000 && e.salary <= 3500) array1.push(e);
            });
            console.log(array1);

            /* 定义*/
            function agetMethods(birthday) {
                return new Date().getFullYear() - birthday.substring(0, birthday.indexOf('.'));
                //console.log(new Date().getFullYear() -  birthday.substring(0, birthday.indexOf('.')));
            }

            function sumMethods(firstNumber, twoNumber) {
                return firstNumber + twoNumber;
            }

            array1.map(v => {
                if (agetMethods(v.birth) <= 19 && v.city != "湖南") {
                    v.age = agetMethods(v.birth);
                    array2.push(v);
                }
            });
            console.log(array2);

            let num = [];
            
            let count = 0;
            
            array2.filter(v => num.push(v.salary));
            
            num.filter(v => count = num.reduce(sumMethods));
            //总和
            console.log(count);

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM