Syntax Cache
BlogMethodFeaturesHow It WorksBuild a Game
  1. Home
  2. JavaScript
  3. JavaScript Collections Practice
JavaScript59 exercises

JavaScript Collections Practice

Arrays, objects, Map, Set, destructuring, spread. Know which tool to reach for and how to use it.

Warm-up1 / 2

Can you write this from memory?

Create an empty Map called `cache`.

JavaScript's spread makes a shallow copy, not a deep one. Object.keys returns strings, even for numeric keys. Map preserves insertion order, objects mostly do. Set uses strict equality.

Small details, real bugs. Practice here tests the collection APIs so you stop making assumptions about how they work.

Related JavaScript Topics
JavaScript FunctionsJavaScript LoopsJavaScript Async/Await

When to Use JavaScript Collections

  • Use Map when keys are not strings or when order matters.
  • Use Set for de-duplication and fast membership checks.
  • Use object/array for simple structured data and JSON.

Check Your Understanding: JavaScript Collections

Prompt

Remove duplicates from an array of ids.

What a strong answer looks like

Use new Set(ids) and spread back into an array: [...new Set(ids)].

What You'll Practice: JavaScript Collections

Array spread and destructuringObject spread and destructuringMap and Set basicsArray methods (find, findIndex, includes)Object.keys/values/entriesOptional chaining (?.) and nullish coalescing (??)

Common JavaScript Collections Pitfalls

  • Shallow vs deep copy with spread
  • Object reference equality
  • Array includes() uses strict equality

JavaScript Collections FAQ

Map vs object?

Map preserves insertion order and allows non-string keys; objects are simpler for JSON-like data.

Does spread make a deep copy?

No, spread only makes a shallow copy of the first level.

JavaScript Collections Syntax Quick Reference

Spread
const merged = { ...obj1, ...obj2 };
Destructuring
const { name, age = 0 } = user;
Optional chain
const city = user?.address?.city ?? "Unknown";

JavaScript Collections Sample Exercises

Example 1Difficulty: 1/5

Create an empty object called `item`.

const item = {};
Example 2Difficulty: 1/5

Create an object `item` with name "hello" and value 1.

const item = { name: "hello", value: 1 };
Example 3Difficulty: 1/5

Access the `name` property of `item`.

item.name

+ 56 more exercises

Quick Reference
JavaScript Collections Cheat Sheet →

Copy-ready syntax examples for quick lookup

Further Reading

  • GDScript Dictionary map() and map_in_place12 min read

Also in Other Languages

Python Collections Practice: Lists, Dicts, Sets & Tuples

Start practicing JavaScript Collections

Free daily exercises with spaced repetition. No credit card required.

← Back to JavaScript Syntax Practice
Syntax Cache

Build syntax muscle memory with spaced repetition.

Product

  • Pricing
  • Our Method
  • Daily Practice
  • Design Patterns
  • Interview Prep

Resources

  • Blog
  • Compare
  • Cheat Sheets
  • Vibe Coding
  • Muscle Memory

Languages

  • Python
  • JavaScript
  • TypeScript
  • Rust
  • SQL
  • GDScript

Legal

  • Terms
  • Privacy
  • Contact

© 2026 Syntax Cache

Cancel anytime in 2 clicks. Keep access until the end of your billing period.

No refunds for partial billing periods.