javascript clear array
arr = []; // set array=[]
//function
const empty = arr => arr.length = 0;
//example
var arr= [1,2,3,4,5];
empty(arr) // arr=[]var colors = ["red","blue","green"];
colors = []; //empty the arraylet aray = [1,2,3,4,5,6,7,8,9,10];
//as with most coding there are several ways you can do anything
//see whichever works best for your scenario
//set the array to equal a blank array
array = [];
//set the array's length to 0
array.length = 0;
//using splice, starts at index 0 & removes everything up to and including that last index
array.splice(0, array.length);
//map or loop through and shift() or pop();
//goes through the array one at a time and removes the last item each time
array.map( () => array.pop());
//goes through the array one at a time and removes the first item each time
array.map( () => array.shift());A.length = 0A.splice(0,A.length)// define Array
let list = [1, 2, 3, 4];
function empty() {
//empty your array
list = [];
}
empty();
Also in JavaScript:
- how to store variable in javascript
- passport middleware check if authenticated
- file ajax
- how to call function on every keypress in jquery
- how to make an if statement in javascript
- set value using javascript
- sum range javascript
- two object combine together javascript
- how to change zoom in and zoom out button position in google map
- drupal tag filter ajax content
- build react app
- javascript hasclass
- js get base url
- ./src/index.js Line 0: Parsing error: Cannot find module '@babel/helper-validator-identifier'
- sort nested data using sort function javascript
- Access to fetch at 'https://api.myip.com/' from origin 'http://localhost:8000' has been blocked by CORS policy: No 'Access-
- async function fetchJson
- add javascript keyup on input
- jquery see if element is visible
- angular back button
- how to get user ip address in javascript
- how to generate random text in vue js
- set multiple attributes javascript
- ajax post rest api example