Do comparison on Javascript object properties and return the rating property
I am doing a simple javascript project where i got an array of objects... and each object has its own properties which include (title)string, rating(int), I have code here that does the comparisons but prints the whole array elements in an ascending manner, Is there a way to make it print the highest value from the comparisons? var fractured={ //Properties title:"Fractured", release:2019, rating:8, format:"digital", genre:[ "Mystery","Sci-Fi","Western"] }; var countdown={ title:"Countdown", release:2018, rating:5, genre:["Sci-Fi","Mystery","Western"] } var bloodshot={ title:"Bloodshot", release:2020, rating:6, format:"digital", genre:["Sci-Fi","Action"] } var nmovies=new Array(fractured,life,crisis,revenant,bloodshot,countdown); //Sorting the movies by rating console.log(nmovies.sort((a, b) => { if (a.rating < b.rating) return -1; if (a.rating > b.rating) return 1; return 0; }));