Hi Guest

HomePage

1 1

To improves our performance please Like Share Subscribe(Will boost us)

Different method to empty an Array in JavaScript?
Question Posted on 14 Apr 2022

Home >> JavaScript >> Javascript Code >> Different method to empty an Array in JavaScript?

Different method to empty an Array in JavaScript?
Below are the different 4 methods to empty an Array in JavaScript:-
Method 1
Below method will set the variable arrayList to a new empty array. And it is recommended to use it if you donot have references to original array arrayList anywhere else. Because this will create a new empty array. Be careful with method of empty array because if you reference array from another variable then the orginal reference array will remain unchanged. Syntax for above is:-
arrayList=[]

Method 2
Below method will clear the existing array by setting its length to 0. And another important facts about this emptying array is that it will updates all the reference variable which point to original array. So this method is useful when we want to update all reference variable pointing to arrayList. Below is the syntax:-
arrayList.length=0;

Method 3
Below method will do the same as above method 2 this will empty the array and also update all the references to original array. And syntax of above method:-
arrayList.splice(0, arrayList.length);

Method 4
This method will empty array but is not recommended to use this method.
while(arrayList.length)
{
arrayList.pop();
}
0
0



Most Visited Questions:-

Deep Learning Questions Answers
Below are the different Deep Leaning Questions and answer a More...

Continuous Integration Questions Answers
Below are the 20 odd questions for CI or Continuous Integra More...

Derived relationships in Association Rule Mining are represented in the form of __________.
Derived relationships in Association Rule Mining are repres More...

What is Gulpjs and some multiple choice questions on Gulp
Gulpjs is an open source whihc helps in building Javascript More...

Microservices Architecture Questions Answers
Below are the different questions on Microservices Architec More...




Other Important Questions
Code to find last occurrence of any word in given sentance or string in Javascript?
Reverse a Array in Javscript by using reverse keyword?
Javascript code to get URL and Its different parts through code?
Function to disable Back Button in javascript
selected radiobuttonlist value in javascript






Most Visited Questions
Top Searches:asp net questions vb net questions sql query uddl questions class javascript Questions sharepoint interview questions and concept silverlight questions and concept wcf questions beans general knowledge ajax questions
PHP | Biztalk | Testing | SAP | HR |
     
 
Privacy policy | Terms and Conditions | Blog


If the copyright of any questions or content or syntax belong to you email us we will remove that(info@crackyourinterview.com or crackyourinterview2018@gmail.com)
 

1
Home About Us GroupChat
 
Sitemap Feedback Contact us