Open In App
Related Articles

p5.js removeItem() Function

Improve Article
Save Article
Like Article

The removeItem() function is used to remove the item that has been stored using the storeItem() function. It removes the value under the given key name from the local storage of the browser.



Parameters: This function accept a single parameter as mentioned above and described below.

  • key: This is a string which denotes the key for which the value has to be removed.

Below example illustrates the removeItem() function in p5.js:


function setup() {
  createCanvas(500, 300);
  text("Use the button to set and retrieve random values", 20, 20);
  setBtn = createButton('Set items to storage');
  setBtn.position(20, 150);
  getBtn = createButton('Get items from storage');
  getBtn.position(20, 180);
  removeBtn = createButton('Remove string to storage');
  removeBtn.position(20, 210);
function retrieveStorage() {
  text("Use the button to set and retrieve random values", 20, 20);
  // retrieve values from local storage
  num = getItem('savedNumber');
  bool = getItem('savedBoolean');
  // display the values
  text("The retrieved items are:", 20, 50);
  text("Number: " + num, 20, 80);
  text("Boolean: " + bool, 20, 100);
function setStorage() {
  // generate random values
  randomNum = floor(random(100));
  randomBool = randomNum > 50 ? true : false;
  // store values to local storage
  storeItem('savedNumber', randomNum);
  storeItem('savedBoolean', randomBool);
function removeStorage() {
  // remove item from local storage


Online editor:
Environment Setup:


Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 21 Aug, 2023
Like Article
Save Article
Similar Reads
Complete Tutorials