O'Reilly logo

A Beginner’s Guide to Writing Minecraft Plugins in JavaScript by Walter Higgins

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required