Case:
var scorestable=[ {id:11,name: "Xiao Zhang", score:80}, {id:22,name: "Xiao Wang", score:95} , {ID:33,name: "Xiao Li", score:50}, {id:44,name: "Xiao Liu", score:65}, {id:55,name: "Xiao Xu" , score:84}]
1. Get the highest score value quickly (using Map,max.sum and apply)
var scores=scorestable.map (function(item) {return item.score}); var maxscore=math.max.apply (This, scores) Console.log (Maxscore)
2. Whether or not to include students who fail (some)
var hasfail=scorestable.some (function(item) {return item.score<60;}) Console.log (Hasfail)
3. averaging (reduce)
var averagescore=scorestable.reduce (function(A, b) {return A + b.score;},0)/ Scorestable.length;console.log (Averagescore)
4. sort by grades from highest to lowest (sort)
var score=scorestable.sort (function(A, b) {return a.score<B.score;}) Console.log (Score)
5. Find a failing student (filter)
var failstudents=scorestable.filter (function(item) {return item.score<60;}) Console.log (failstudents)
6, whether all students of the school number is a multiple of 11 (every)
var t=scorestable.every (function(item) {return item.id%11==0;}) Console.log (t)
JavaScript uses Map,every,filter,some,reduce,sort to optimize the processing of arrays