Remove value from array

suggest change

When you need to remove a specific value from an array, you can use the following one-liner to create a copy array without the given value:

array.filter(function(val) { return val !== to_remove; });

Or if you want to change the array itself without creating a copy (for example if you write a function that get an array as a function and manipulates it) you can use this snippet:

while (index = array.indexOf(3) !== -1) { array.splice(index, 1); }

And if you need to remove just the first value found, remove the while loop:

var index = array.indexOf(to_remove);
if (index !== -1) { array.splice(index , 1); }

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:


Arrays:
* Syntax
* Remove value from array

Table Of Contents
11 Arrays
12 Objects
14 Classes
16 Map
17 Set
24 Loops
27 Date
29 Scope
30 AJAX
35 Cookies
41 JSON
44 Fetch
45 Modules
46 Screen
64 Console
68 Symbols
73 Modals
76 Events
86 Proxy
89 WeakMap
90 WeakSet
102 Tilde