Difference between revisions of "Remove"
Jump to navigation
Jump to search
(Created page with "<c>remove</c> removes part of a list, map, or string. See also: indexOf === Arguments === {| class="wikitable" |- ! Parameter Name !! Default Value !! Meaning |- | ''se...") |
m (→Arguments) |
||
| (3 intermediate revisions by 2 users not shown) | |||
| Line 7: | Line 7: | ||
{| class="wikitable" | {| class="wikitable" | ||
|- | |- | ||
| − | ! Parameter Name !! | + | ! Parameter Name !! Type !! Meaning |
|- | |- | ||
| ''self'' || list, map, or string || object to remove something from | | ''self'' || list, map, or string || object to remove something from | ||
| + | |- | ||
| + | | ''k'' || number or string || element index or substring to remove | ||
|} | |} | ||
=== Usage Notes === | === Usage Notes === | ||
Exact behavior of <c>remove</c> depends on the data type of self: | Exact behavior of <c>remove</c> depends on the data type of self: | ||
| + | |||
list: removes one element by its index; the list is mutated in place; | list: removes one element by its index; the list is mutated in place; | ||
| − | returns null, and throws an error if the given index out of range | + | returns null, and throws an error if the given index out of range. |
| + | |||
map: removes one key/value pair by key; the map is mutated in place; | map: removes one key/value pair by key; the map is mutated in place; | ||
| − | returns 1 if key was found, 0 otherwise string: returns a new string with the first occurrence of k removed | + | returns 1 if key was found, 0 otherwise. |
| + | |||
| + | string: returns a new string with the first occurrence of k removed. | ||
| + | |||
May be called with function syntax or dot syntax. | May be called with function syntax or dot syntax. | ||
Latest revision as of 21:06, 17 November 2023
remove removes part of a list, map, or string.
See also: indexOf
Arguments
| Parameter Name | Type | Meaning |
|---|---|---|
| self | list, map, or string | object to remove something from |
| k | number or string | element index or substring to remove |
Usage Notes
Exact behavior of remove depends on the data type of self:
list: removes one element by its index; the list is mutated in place; returns null, and throws an error if the given index out of range.
map: removes one key/value pair by key; the map is mutated in place; returns 1 if key was found, 0 otherwise.
string: returns a new string with the first occurrence of k removed.
May be called with function syntax or dot syntax.
Example
a=["a","b","c"]; a.remove 1 // leaves a == ["a", "c"]
d={"ichi":"one"}; d.remove "ni" // returns 0
"Spam".remove("S") // returns "pam"