Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

object loop javascript

const shots = [
            {id: 1, salary:100,name:'Win Win Maw',position:'junior'},
            {id: 2, salary:130,name:'Mg Mg',position:'junior'},
            {id: 3, salary:200,name:'KO KO',position:'senior'},
            {id: 4, salary:90,name:'Hla Hla',position:'intern'},
            {id: 5,  salary:250,name:'Ni Lar',position:'senior'},
            ];

            let maxName = null;
            let maxSalary = 0;
            let maxPositon = null;


            

            
            // maxSalary = shots.reduce((acc, shot) => acc = acc > shot.salary ? acc : shot.salary, 0);

            for(const [salary,position] of Object.entries(shots)){
                if(maxSalary < salary){
                    maxSalary = salary;
                    maxPositon = position
                }
            }
            console.log(maxPositon.name,maxPositon.salary,maxPositon.position);
Source by developer.mozilla.org #
 
PREVIOUS NEXT
Tagged: #object #loop #javascript
ADD COMMENT
Topic
Name
5+5 =