Close Menu
    Facebook X (Twitter) Instagram
    TecAdmin
    • Home
    • FeedBack
    • Submit Article
    • About Us
    Facebook X (Twitter) Instagram
    TecAdmin
    You are at:Home»Programming»JavaScript»How to Empty an Array in JavaScript

    How to Empty an Array in JavaScript

    By RahulMay 6, 20191 Min Read

    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

    Related Posts

    Passing Array to a Function in Java

    Diverse Ways to Instantiate Objects in JavaScript

    JavaScript Code to Detect Web Browser

    Add A Comment

    Leave A Reply Cancel Reply

    Advertisement
    Recent Posts
    • How to Change Port in Next.Js
    • Ubuntu 24.04 LTS: The Future of Open-Source Excellence
    • How to Execute Linux Commands in Python
    • Creating MySQL User with GRANT OPTION
    • Where to find crontab (cron) logs in Ubuntu & Debian
    Facebook X (Twitter) Instagram Pinterest
    © 2023 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

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