arrayDelete

Deletes the first element in an array that matches the value of object.
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, object) → returns boolean

Member Function Syntax

someArray.delete(object)

Argument Reference for the arrayDelete function

array

Required: Yes

object

Required: Yes
A string, numeric or boolean value on which to search. Case sensitive.

scope

Required: No
Default: one
Lucee 4.5+ remove one (default) or all occurances of the object Values:
  • one
  • all

Examples sample code invoking the arrayDelete function


Delete an element from an array

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']


Delete an element from an array using the Array member function

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']


Use of scope parameter

Lucee 4.5+ Use scope to remove one or all occurances of the object

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

writeDump(arr);

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


Fork me on GitHub