Linked Questions
115 questions linked to/from How do I empty an array in JavaScript?
62 votes
5 answers
78k views
Is JavaScript's array.clear() not a function? [duplicate]
I'm trying to empty an array containing my drawn coordinates when a button "clear" is pressed. When I call drawnDivs.clear(), I get an error that it is not a function. drawnDivs is certainly an array,...
31 votes
4 answers
52k views
How to remove elements from Array? [duplicate]
Possible Duplicate: how to empty an array in JavaScript How to remove all items from jQuery array? I have array var myArray = [];, I want to clear all items in this array on every post back.
11 votes
4 answers
8k views
Javascript- is there a way to destroy all elements of an array by one command? [duplicate]
my script creates an empty array and then fill it. But if new arguments come then script is expected to destroy old one and create new one. var Passengers = new Array(); function FillPassengers(...
4 votes
3 answers
13k views
How to clear the jsonArray in javascript [duplicate]
Possible Duplicate: how to empty an array in JavaScript var jsonParent = []; This is my jsonArray I am pushing some elements in the array, but now I want to empty this array and remove all ...
3 votes
2 answers
4k views
How to remove all the elements from array [duplicate]
I have an array eg: a[3,4,5,6,7,8]. I want to remove all the element in one time and make array as an empty array. How to remove all the element of an array. My code var a = [2,3,4,5,6]; for(var i=...
10 votes
2 answers
1k views
In JavaScript, what's the difference between myArray.length = 0 vs myArray = new Array()? [duplicate]
Regarding JavaScript, when clearing an array, I've found two methods: myArray.length = 0; vs myArray = new Array() I would guess myArray.length = 0; keeps the reference while myArray = newArray() ...
3 votes
4 answers
3k views
Clearing objects from Javascript array [duplicate]
Possible Duplicate: how to empty an array in JavaScript Best way to deallocate an array of array in javascript I have an array of objects: var arr = [complexObj1, complexObj2]; If I want to ...
4 votes
1 answer
681 views
Why can i empty one array if it is a reference type? [duplicate]
I'm currently learning arrays in JS. Whats puzzling me is that an array like an object is a reference type. So with that in mind if I create a new reference (variable) to the same array and empty ...
4 votes
2 answers
324 views
Difference between create a new Array and clear the length [duplicate]
If I have to delete all the items in an array, what's the difference between using new Array and length = 0? In the example, apparently the result looks the same. function MyCtrl($scope) { ...
0 votes
1 answer
1k views
On change delete everything in array and add new values in it [duplicate]
I have function, which on change calling method 'saveSelectedValue'. this.$filtercat.on('change', { that : this }, this.saveSelectedValue); This method does only one thing: saving data in array. ...
3 votes
2 answers
336 views
How to empty an array in JavaScript? [duplicate]
I am using ArrayList as my array, let ArrayList = ['a','b','c','d','e','f']; I am confused in between Method 1 and Method 2 because in both case I Referenced ArrayList by another you can also ...
1 vote
3 answers
195 views
How would you remove all objects from an array? [duplicate]
So, how would you remove all objects from an array.. My current code is: var array = [""]; function add() { var input = document.getElementById("enterInput")....
0 votes
4 answers
259 views
Reset an array through function parameter [duplicate]
I am trying to reset an array through a function parameter. Here is my code: <script> fruitArray = ["apple", "banana", "orange", "pineapple"] function newFruit(myArray){ myArray=[]; } ...
1 vote
1 answer
135 views
How to empty an array [duplicate]
im working on a game(snake) with obstacles, when the user get their score to 5 I create more blocks as obstacles: wall = new Array(), wall.push(new Rectangle(30, 50, 10, 10)); is there a clear/empty ...
0 votes
2 answers
70 views
What is the proper way to delete all elements from an array? [duplicate]
I am having trouble in deleting all elements from an array in mongodb. This is my schema: const userSchema=mongoose.Schema({ name: String, email: String, password: String, blog: [{ ...