Show Output
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Empty an Array in JavaScript</title> </head> <body> <script> var arr1 = [1,2,3,4,5]; // Reference arr1 by another variable var arr2 = arr1; // Making arr1 empty arr1.length = 0; document.write(arr1.length + "<br>"); // Prints: 0 document.write(arr2.length); // Prints: 0 </script> </body> </html>