We can remove an element of an array in TypeScript using the pop()
method. This method removes the last element of the array and returns that element.
array.pop()
array: This is the array whose last element we want to remove.
The value returned is the element that was removed.
// create arrays in TypeScriptlet names: string[] = ["Theodore", "James", "Peter", "Amaka"]let numbers : Array<number>;numbers = [12, 34, 5, 0.9]let cars : Array<string> = ["Porsche", "Toyota", "Lexus"]// print previous arraysconsole.log("Previous Arrays")console.log(names)console.log(numbers)console.log(cars)// pop and print last elementsconsole.log(names.pop())console.log(numbers.pop())console.log(cars.pop())// print modified arraysconsole.log("\nCurrent Arrays")console.log(names)console.log(numbers)console.log(cars)