How do I empty an array in JavaScript?

JavascriptWeb DevelopmentFront End Technology

To empty an array in JavaScript, set the variable to empty:

arr = []

Example

You can try to run the following code to empty an array in JavaScript:

<html>
   <head>
      <title>JavaScript Arrays</title>
   </head>
   <body>
      <script>
         var arr = ["orange", "mango", "banana", "sugar", "tea"];
         document.write("<br />Original array: " + arr );
   
         arr = [];
         document.write("<br />Current array: " + arr );
      </script>
   </body>
 </html>
raja
Published on 08-Feb-2018 13:11:31
Advertisements