Clearing all items

Sometimes, you might find while experimenting that you've put a lot of useless key-value pairs inside your storage. You can clear them all at once with the clear method in session storage, as shown in the following snippet:

sessionStorage.clear();console.log(sessionStorage); // blank object {}

Get Learn ECMAScript - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.