Monday, April 29, 2019

javascript - How to remove elements from Array?










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.


Answer



Simplest thing to do is just



myArray = [];


again.



edit — as pointed out in the comments, and in answers to other questions, another "simplest thing" is




myArray.length = 0;


and that has the advantage of retaining the same array object.


No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...