Sikau

JavaScript · Day 63 · about 25 min

More array tools

Sorting, slicing and copying lists.

Lists, your way

Leaderboards need sorting, pages show the first ten results, and sometimes you need a copy of a list so the original stays safe. Let's round out your array toolbox.

Sorting

const names = ["Sita", "asha", "Bikash"];
console.log([...names].sort());

const scores = [40, 100, 9];
console.log([...scores].sort());
console.log([...scores].sort((a, b) => a - b));
console.log([...scores].sort((a, b) => b - a));

The rest of this lesson

  • Slicing and findingexplain
  • Which methods change the array?explain
  • Predict the outputpredict
  • Mutating or not?match
  • Your turnwrite code
  • Badge quizquiz
  • What you learnedrecap

Continue this lesson free — run real code in your browser

Continue with Google

See all 68 lessons of JavaScript