Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

StorageArea.remove()

我们的志愿者还没有将这篇文章翻译为 中文 (简体)加入我们帮助完成翻译!

Removes one or more items from the storage area.

Syntax

chrome.storage.<storageType>.remove(
  keys,             // string, or array of strings
  function(){...}   // function
)

This API is also available as browser.storage.<storageType>.remove() in a version that returns a promise.

<storageType> will be one of the writable storage types — storage.sync or storage.local.

Parameters

keys
A string, or array of strings, representing the key(s) of the item(s) to be removed.
callback Optional
A callback function that is run when the operation completes. The callback takes no arguments. If the operation failed, runtime.lastError is set.

Browser compatibility

Chrome Edge Firefox Firefox for Android Opera
Basic support Yes Yes 45.0 48.0 33

Examples

Remove a single item, callback version:

// callback to remove() just checks for errors
function onRemoved() {
  if (chrome.runtime.lastError) {
    console.log(chrome.runtime.lastError);
  } else {
    console.log("OK");
  }
}

chrome.storage.local.remove("kitten", onRemoved);

Remove multiple items, callback version:

// callback to remove() just checks for errors
function onRemoved() {
  if (chrome.runtime.lastError) {
    console.log(chrome.runtime.lastError);
  } else {
    console.log("OK");
  }
}

chrome.storage.local.remove(["kitten", "grapefruit"], onRemoved);

Remove single item, promise version:

function onRemoved() {
  console.log("OK");
}

function onError(e) {
  console.log(e);
}

var removeKitten = browser.storage.remove("kitten");
removeKitten.then(onRemoved, onError);

Example add-ons

Acknowledgements

This API is based on Chromium's chrome.storage API. This documentation is derived from storage.json in the Chromium code.

Microsoft Edge compatibility data is supplied by Microsoft Corporation and is included here under the Creative Commons Attribution 3.0 United States License.

文档标签和贡献者

 此页面的贡献者: Makyen, wbamberg, chrisdavidmills
 最后编辑者: Makyen,