remove all array elements javascript code example
Example 1: remove array elements javascript
let value = 3
let arr = [1, 2, 3, 4, 5, 3]
arr = arr.filter(item => item !== value)
console.log(arr)
Example 2: remove array elements javascript
let forDeletion = [2, 3, 5]
let arr = [1, 2, 3, 4, 5, 3]
arr = arr.filter(item => !forDeletion.includes(item))
console.log(arr)
Example 3: javascript empty array
arr = [];
const empty = arr => arr.length = 0;
var arr= [1,2,3,4,5];
empty(arr)
Example 4: js delete all from array
var list = [1, 2, 3, 4];
function empty() {
list.length = 0;
}
empty();