How do I remove an array item in TypeScript?
let foo_object; // Itemitem(object here) to remove
this.foo_objects = this.foo_objects.filter(obj => return obj !== foo_object);
Same way as you would in JavaScript.
delete myArray[key];
Note that this sets the element to undefined
.
Better to use the Array.prototype.splice
function:
const index = myArray.indexOf(key, 0);
if (index > -1) {
myArray.splice(index, 1);
}