How to remove elements from Array?

arrays, javascript

Solution

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.

Problem

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.

Original source

Related problems