arrayDelete

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

Member Function Syntax

someArray.delete(value)

arrayDelete Argument Reference

array array
Required

value any
Required

A value for which to search. Case-sensitive.

scope string
Default: one

Lucee 4.5+ remove one (default) or all occurrences of the value
Values:
  • one
  • all

Examples sample code invoking the arrayDelete function

Uses the arrayDelete function to delete an element from an array

arr = ['apple', 'orange', 'pear', 'apple'];
arrayDelete(arr, 'apple');

writeDump(arr);

Expected Result: ['orange','pear','apple']

CF 11+ Lucee 4.5+ Invoking the delete function on an array is the same as running arrayDelete.

arr = ['apple', 'orange', 'pear', 'apple'];
arr.delete('apple');

writeDump(arr);

Expected Result: ['orange','pear','apple']

Lucee 4.5+ Use scope to remove one or all occurrences of the value

arr = ['apple', 'orange', 'pear', 'apple'];
arr.delete('apple', 'all');

writeDump(arr);

Expected Result: ['orange','pear']


Fork me on GitHub