Facebook Twitter Instagram
    TecAdmin
    • Home
    • FeedBack
    • Submit Article
    • About Us
    Facebook 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.

    Advertisement

    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

    How to list all collections in MongoDB database

    What is difference between var, let and const in JavaScript?

    What is difference between var, let and const in JavaScript?

    How do I Replace String in JavaScript

    How to Replace String in JavaScript

    Add A Comment

    Leave A Reply Cancel Reply

    Advertisement
    Recent Posts
    • How to Split Large Archives in Linux using the Command Line
    • System.out.println() Method in Java: A Beginner’s Guide
    • Split Command in Linux With Examples (Split Large Files)
    • Test Your Internet Speed from the Linux Terminal
    • 11 Practical Example of cat Command in Linux
    Facebook Twitter Instagram Pinterest
    © 2023 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

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