+ 3

Removing items from an Array in JavaScript

How would one remove an item from an Array in JavaScript?

20th Mar 2018, 5:34 PM
Leroy Jenkins
Leroy Jenkins - avatar
4 Answers
+ 3
With splice array.splice(array.indexOf("item"), 1); Associative array or object delete array["key"];
20th Mar 2018, 5:37 PM
Toni Isotalo
Toni Isotalo - avatar
+ 6
You can use pop() or shift() to remove elements (pop() removes the last element while shift() removes the first one) To remove an element from a given position, slice() is usually used, although there are other ways. Here you have more information: https://www.w3schools.com/js/js_array_methods.asp
20th Mar 2018, 5:46 PM
Mickel
Mickel - avatar
+ 3
thank you so much!
20th Mar 2018, 5:41 PM
Leroy Jenkins
Leroy Jenkins - avatar
+ 3
I like the: delete name[index] the best:)
20th Mar 2018, 6:02 PM
Leroy Jenkins
Leroy Jenkins - avatar