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