Easy way to pop() your Array List

I have been working on Arrays in Flash and had to repopulate the array with the new set of values. I have been using array.pop() method to empty the list with a for loop, currently I found an easier way


   1:  var a_arr:Array = new Array("one","two","three");
   2:  var b_arr:Array = new Array("one","two","three");
   4:  function clearArray(arr:Array):Void
   5:  {
   6:      arr.splice(0,arr.length);
// splice removes elements from index,count
   7:  }
   8:  function oldarraypopmethod(arr:Array):Void
   9:  {
  10:     for(var i:Number=0;i
  11:     arr.pop();
  12:  }
  13:  // new method 
  14:  trace("before a_arr"+ a_arr.toString());
  15:  clearArray(a_arr);
  16:  trace("after a_arr"+ a_arr.toString());
  17:  trace("before b_arr"+ b_arr.toString());
  18:  oldarraypopmethod(b_arr);
  19:  trace("after b_arr"+ b_arr.toString());
I find the new Method doesn't take too much line. 
The above line of code can be applied to JavaScript too.


One thought on “Easy way to pop() your Array List

  1. i guess the solution can be even like this :

    var a_arr:Array = new Array(“one”,“two”,“three”);
    var b_arr:Array = new Array(“one”,“two”,“three”);
    a_arr = [];//to clear the array.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s