javascript create empty array of size code example

Example 1: javascript empty array

var colors = ["red","blue","green"];
    colors = []; //empty the array

Example 2: create empty array javascript

const myArray1 = []
// or...
const myArray2 = new Array()

Example 3: empty array js

// define Array
let list = [1, 2, 3, 4];
function empty() {
    //empty your array
    list = [];
}
empty();

Example 4: empty array javascript

let myArray = [12 , 222 , 1000 ];  
myArray.length = 0; // myArray will be equal to [].

Example 5: empty array length javascript

empty array check javascript