Monday 29 April 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

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...