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);
}
Answer from blorkfish on Stack OverflowSame 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);
}
let foo_object; // Itemitem(object here) to remove
this.foo_objects = this.foo_objects.filter(obj => return obj !== foo_object);
Videos
I'm just looking for something along the lines of:
array.remove("element")Upon Googling for solutions so far I've found
Remove an element at any index with splice
Remove an element from an array with a for loop and push
Remove an element at any position of an array with slice and concat
There's more but I'm assuming you get the point. Why is this seemingly simple task so ridiculously complicated with Javascript?
Did nobody think to include a ".remove()" method when they were first developing Javascript? Is there a quirk of the language that makes it impossible? What is the reason for this?