Deletes the first element in an array that matches the value of value
.
The search is case-sensitive.
Returns true
if the element was found and removed.
The array will be resized, so that the deleted element doesn’t leave a gap.
arrayDelete(array, value)
returns boolean
someArray.delete(value)
Name | Type | Required | Default | Description | Values | |
---|---|---|---|---|---|---|
array | array | Yes | ||||
value | any | Yes | A value for which to search. Case-sensitive. | |||
scope | string | No | one | Lucee4.5+ remove one (default) or all occurrences of the value | /Users/garethedwards/development/github/cfdocs/docs/functions/arraydelete.md | all |
Uses the arrayDelete function to delete an element from an array
arr = ['apple', 'orange', 'pear', 'apple'];
arrayDelete(arr, 'apple');
writeDump(arr);
CF11+ Lucee4.5+ Invoking the delete function on an array is the same as running arrayDelete.
arr = ['apple', 'orange', 'pear', 'apple'];
arr.delete('apple');
writeDump(arr);
Lucee4.5+ Use scope to remove one or all occurrences of the value
arr = ['apple', 'orange', 'pear', 'apple'];
arr.delete('apple', 'all');
writeDump(arr);