Storage

localStorage.removeItem

Removes the key/value pair with the given key from the localStorage object

Syntax

JavaScript
localStorage.removeItem(key)

Parameters

ParameterTypeDescription
keystringThe name of the key to remove

Return Value

undefined

Examples

Basic Usage
localStorage.removeItem('auth_token')
console.log(localStorage.getItem('auth_token')) // null
Practical Example
function logout() {
  localStorage.removeItem('user')
  localStorage.removeItem('token')
  window.location.href = '/login'
}
Advanced Usage
function clearOldData(prefix: string) {
  const keys = Object.keys(localStorage).filter(k => k.startsWith(prefix))
  keys.forEach(k => localStorage.removeItem(k))
}

Understanding localStorage.removeItem

The localStorage.removeItem method in JavaScript removes the key/value pair with the given key from the localStorage object. It belongs to the Storage object and is one of the most widely used methods for working with storage values in modern JavaScript and TypeScript applications.

The method signature is localStorage.removeItem(key). It accepts 1 parameter: key. When called, it returns undefined. Understanding when and how to use removeItem() helps you write more expressive, readable code.

Common use cases for localStorage.removeItem include data transformation, input validation, API response processing, and building reusable utility functions. It works well alongside related methods like localstorage-setitem, localstorage-getitem, localstorage-clear, enabling you to chain operations together for complex data manipulation pipelines.

Browser support for localStorage.removeItem is excellent across all modern browsers including Chrome, Firefox, Safari, and Edge. It is also fully supported in Node.js and Deno. For older environments, transpilation with Babel or a polyfill may be needed.

Browser Compatibility

Supported in all modern browsers (Chrome, Firefox, Safari, Edge) and Node.js. Part of the ECMAScript standard.

Related Methods

More Storage Methods

Other methods in the Storage object

Related Tools

More Storage Methods

Explore JavaScript Methods

Browse our complete reference of 410 JavaScript methods with syntax, examples, and explanations.