remove all element of array before add new one in js code example
Example 1: js delete all array items
A.splice(0,A.length)
Example 2: remove element from array javascript
//using filter() method => it returns a new array
data = [1, 2, 3, 4, 5, 6];
let filteredData = data.filter((i) => {
return i > 2
});
console.log(filteredData) // [3, 4, 5, 6]