10 examples of 'js remove all elements from array' in JavaScript

Every line of 'js remove all elements from array' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
11function remove(array, element) {
12 const index = array.indexOf(element);
13 array.splice(index, 1);
14}
11export function removeArray(array, val, callback) {
12 var index = array.indexOf(val);
13 //如果找到
14 if (index > -1) {
15 callback && callback()
16 array.splice(index, 1);
17 }
18}
171function remove(array, el) {
172 var i;
173 for (i = array.length - 1; i > -1; i-=1) {
174 if (array[i] === el) {
175 array.splice(i, 1);
176 }
177 }
178}
16function removeFromArray(array, element) {
17 var index = array.indexOf(element);
18
19 if (index !== -1) {
20 array.splice(index, 1);
21 }
22}
54function remove_element(array, elem) {
55 var index = array.indexOf(elem);
56 if (index > -1) {
57 array.splice(index, 1);
58 }
59}
48export function remove(array, index) {
49 var len = array.length - 1;
50
51 var out = new Array(len);
52
53 var i = 0;
54 while (i < index) {
55 out[i] = array[i];
56 ++i;
57 }
58
59 while (i < len) {
60 out[i] = array[i + 1];
61 ++i;
62 }
63
64 return out;
65}
76function remove(els) {
77 utils.asArray(els).forEach(function (el) {
78 removeEl(el);
79 });
80}
8function remove(arr, ele) {
9 if (contain(arr, ele)) {
10 arr.splice(arr.indexOf(ele), 1);
11 }
12 return arr;
13}
341static removeValue(array, value) {
342 for (var tI = array.length - 1; tI >= 0; tI--) {
343 if (array[tI] === value) {
344 array.splice(tI, 1);
345 }
346 }
347}
4function remove_element(arr, val) {
5 var i = arr.indexOf(val);
6 return i>-1 ? arr.splice(i, 1) : [];
7 };

Related snippets