Skip to content

Array.remove method

Array › remove

Official

Removes an element from the array, if it exists, otherwise returns the array unchanged.

Signature:

remove(target: T): void

Parameters:

Parameter Type Description
target T The element to remove.

Returns: void

Example:

let arr = [1, 2, 3];
arr.remove(2);
console.log(arr); // [1, 3]
arr = [1, 2, 3];
arr.remove(4);
console.log(arr); // [1, 2, 3]