Answers for "emptying out an array in javascript"

6

Javascript remove empty elements from array

var colors=["red","blue",,null,undefined,,"green"];

//remove null and undefined elements from colors
var realColors = colors.filter(function (e) {return e != null;});
console.log(realColors);
Posted by: Guest on July-25-2019
0

javascript empty array

var arr1 = ['a','b','c','d','e','f'];
var arr2 = arr1;  // Reference arr1 by another variable 
arr1 = [];
console.log(arr2); // Output ['a','b','c','d','e','f']
Posted by: Guest on October-23-2020

Code answers related to "emptying out an array in javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language