Array.remove Function

Removes the first occurrence of the specified item from an Array object. This function is static and can be invoked without creating an instance of the object.

var isRemoved = Array.remove(array, item);

Arguments

  • array
    The array to remove item from.

  • item
    The object to remove from the array at the first occurrence.

Return Value

true if the specified item exists as element in the array and was removed; otherwise, false.

Remarks

Use the remove function to remove the first occurrence of a specified item from an array. The index value of items that remain in the array is decreased by one.

In Mozilla Firefox, calling the remove function with item set to undefined removes the first item with that value from the array. In other browsers, calling the function with item set to undefined has no effect.

Example

The following example shows how to use the remove function to remove the first occurrence of an item from an array.

var a = ['a', 'b', 'c', 'd', 'e'];
Array.remove(a, 'c');
// View the results: "a,b,d,e"
alert(a);
Array.removeAt(a, 2);
 // View the results: "a,b,e"
alert(a);

See Also

Reference

Array.dequeue Function

Array Object

Array Type Extensions

Other Resources

Language Reference