JavaScript Array Exercises with Hints and Solutions

Practise turning arrays of objects into useful results. These six beginner exercises use phones, carts, books, tags and orders to make filtering, sorting, counting and string handling easier to understand.

Start with arrays, object properties, booleans and basic arithmetic. An arrow-function callback is useful, but a for...of loop can help you understand the steps first.

What you will practise

Choose matching records

Use filter to keep phones that are in stock, then map those records to model names.

Combine rows into one result

Multiply each cart item’s price by quantity, then accumulate the amounts with a loop or reduce. Count orders by status with the same technique.

Sort without surprises

Copy an array before sorting it and use a numeric comparator, so the original order stays intact and 1000 does not sort before 200.

Clean and reshape values

Remove duplicates with a Set and turn a lowercase title into Title Case with split, map and join.

6 exercises to try

Sort books by price

Sort the books from cheapest to most expensive without changing the original array. Print the titles on one line, then print the title of the first item in the original array to prove it did not move.

Open lesson and hints

How to use these exercises

Predict the expected result, run a small attempt, then reveal a hint only if needed. Compare the values rather than console formatting. After the walkthrough, try an empty array and explain why the result makes sense.

Runtime and progress

These exercises run in the browser JavaScript playground. They are for snippets rather than a Node.js server or an npm project.

Completion is self-reported. There is no automated grading, and progress is saved only on this device.

Browse every practice topic