Chapter 11. Leaderboards: More Fun with Arrays

One of the really cool things about arrays in JavaScript is that they can be sorted. Sorting is the process of looking at each item in an array and deciding whether it is greater than or less than another item in the same array. When all of the items in an array are sorted, the array is like a leaderboard—a ranked list of items. In this chapter, you’ll create a ranked list of players based on who has jumped most.

Array.sort()

The Array.sort() method is used to sort items in an array. Let’s see it in action. Issue the following commands at the server console prompt:

js var animals = ['pig','wolf','cow','cat','sheep'];js console.log( animals );> pig,wolf,cat,cow,sheep ...

Get A Beginner’s Guide to Writing Minecraft Plugins in JavaScript now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.