Data Handling in JavaScript

Data Handling = two more ways to store data, and how data travels as text.

This chapter has 2 lessons and 10 exercises you run and check in your browser. Plan on about 59 minutes.

  • Collections: Map for lookups and Set for unique values.
  • JSON Handling: JSON.stringify, JSON.parse and handling bad JSON safely.

After this chapter, you can:

  • Look things up by any key with a Map.
  • Remove duplicates and check membership with a Set.
  • Turn data into JSON text and back again.
  • Catch broken JSON before it crashes the page.

Every lesson has short explanations, code boxes you edit and run in the live editor, and a web page example you can click.

Before you start, finish Objects.

Next chapter: Error Handling.

Lessons in this section

  1. Collections

    Why Map and Set exist alongside objects and arrays, every Map and Set method, removing duplicates, converting between arrays, Sets, objects and Maps, and looping over collections with for...of and forEach().

    • Choose between an object, a Map and a Set
    • Create a Map and use set(), get(), has(), delete(), clear() and size
    • Read a Map's keys, values and entries
    • Create a Set and use add(), has(), delete(), clear() and size
  2. JSON Handling

    What JSON is and how it differs from a JavaScript object, JSON structure, JSON.stringify() with indentation, JSON.parse(), the values JSON cannot carry, replacers, revivers and toJSON, and the common JSON errors and how to parse safely.

    • Explain what JSON is and how it differs from a JavaScript object
    • Read and write JSON objects, arrays and nested data
    • Convert values to JSON text with JSON.stringify(), including indentation
    • Convert JSON text back into values with JSON.parse()