GM.deleteValue: Difference between revisions
From GreaseSpot Wiki
Jump to navigationJump to search
m Text replace - "top " to "" |
Update for 4.0 |
||
(12 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
== Description == | == Description == | ||
This method deletes an existing name / value pair from storage. | |||
See [[GM.setValue]] for details regarding the storage of these values. | |||
== Syntax == | == Syntax == | ||
{{Function|GM.deleteValue|name}} | |||
Compatibility: [[Version_history#4.0_2|Greasemonkey 4.0+]] | |||
== Arguments == | |||
; <code>name</code> | |||
: Property name to delete. See [[GM.setValue#Arguments|GM.setValue]] for details on what names are valid. | |||
: | |||
== Returns == | |||
[[ | A [[Promise]], resolved successfully with no value on success, rejected with no value on failure. | ||
== Examples == | == Examples == | ||
Delete the stored name / value pair that has the name 'foo': | |||
</pre>}} | <pre class='sample'> | ||
GM.deleteValue("foo"); | |||
</pre> | |||
Example showing the use of [[GM.listValues]] to delete ''all'' stored name / value pairs: | |||
<pre class='sample'> | |||
let keys = await GM.listValues(); | |||
for (let key of keys) { | |||
GM.deleteValue(key); | |||
} | |||
</pre> | |||
Similar example to the above, but with a filter within the loop to exclude 'a' and 'foo' and 'bar' from deletion: | |||
<pre class='sample'> | |||
let keysToKeep = ['a', 'foo', 'bar']; | |||
let keys = await GM.listValues(); | |||
for (let key of keys) { | |||
if (!keysToKeep.includes(key)) { | |||
GM.deleteValue(key); | |||
} | |||
} | |||
</pre> | |||
== See Also == | == See Also == | ||
* [[GM.getValue]] | |||
* [[GM.setValue]] | |||
* [[GM.listValues]] | |||
[[Category:API_Reference|D]] | [[Category:API_Reference|D]] |
Latest revision as of 14:23, 3 November 2017
Description
This method deletes an existing name / value pair from storage.
See GM.setValue for details regarding the storage of these values.
Syntax
function GM.deleteValue( name )
Compatibility: Greasemonkey 4.0+
Arguments
name
- Property name to delete. See GM.setValue for details on what names are valid.
Returns
A Promise, resolved successfully with no value on success, rejected with no value on failure.
Examples
Delete the stored name / value pair that has the name 'foo':
GM.deleteValue("foo");
Example showing the use of GM.listValues to delete all stored name / value pairs:
let keys = await GM.listValues(); for (let key of keys) { GM.deleteValue(key); }
Similar example to the above, but with a filter within the loop to exclude 'a' and 'foo' and 'bar' from deletion:
let keysToKeep = ['a', 'foo', 'bar']; let keys = await GM.listValues(); for (let key of keys) { if (!keysToKeep.includes(key)) { GM.deleteValue(key); } }