Facebook Twitter Instagram
    TecAdmin
    • Home
    • Ubuntu 20.04
      • Upgrade Ubuntu
      • Install Java
      • Install Node.js
      • Install Docker
      • Install LAMP Stack
    • Tutorials
      • AWS
      • Shell Scripting
      • Docker
      • Git
      • MongoDB
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    Home»Programming»JavaScript»How to Empty an Array in JavaScript

    How to Empty an Array in JavaScript

    RahulBy RahulApril 24, 20191 Min ReadUpdated:May 6, 2019

    An array is a container of multiple values of similar types. After initializing an array, how can you empty it? This tutorial will help you to empty an Array in JavaScript language.

    Empty Array in JavaScript

    Use the following syntax to empty an Array. Here myArray is the name of Array.

    myArray = [];
    

    The above code will create an Array named myArray with no content. If the myArray already exists, will lose all the existing elements.

    You can also set the length to 0 to make it empty.

    myArray.length = 0
    
    array javascript js
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp
    Previous ArticleHow to List All files in a Directory using Python
    Next Article How To Install Dovecot on Ubuntu 18.04 & 16.04 LTS

    Related Posts

    How to Replace String in JavaScript

    Updated:June 13, 20222 Mins Read

    5 Methods to Print an Array in Java

    Updated:April 21, 20222 Mins Read

    JavaScript Program to Add Two Numbers

    Updated:June 9, 20222 Mins Read

    How to Install ReactJS on Ubuntu 20.04

    3 Mins Read

    Remove First Character from String in JavaScript

    1 Min Read

    10 Useful JavaScript Console Methods

    Updated:June 9, 20223 Mins Read

    Leave A Reply Cancel Reply

    Recent Posts
    • What is CPU? – Definition, Types and Parts
    • What is the /etc/aliases file
    • What is the /etc/nsswitch.conf file in Linux
    • How to Install Ionic Framework on Ubuntu 22.04
    • What is the /etc/hosts file in Linux
    Facebook Twitter Instagram Pinterest
    © 2022 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.