To remove a specific element from an array in TypeScript, you can use the `splice` method or create a new array excluding the element to be removed.
In this example,
let numbers: number[] = [1, 2, 3, 4, 5];
let indexToRemove: number = numbers.indexOf(3);
numbers.splice(indexToRemove, 1);
console.log(`Array after removing 3: ${numbers}`);
Array after removing 3: 1,2,4,5
In this example,
let colors: string[] = ['red', 'green', 'blue', 'yellow'];
let elementToRemove: string = 'green';
let newArray: string[] = colors.filter(color => color !== elementToRemove);
console.log(`Array after removing ${elementToRemove}: ${newArray}`);
Array after removing green: red,blue,yellow
In this tutorial, we learned How to Remove Specific Element from an Array in TypeScript language with well detailed examples.