Dynamically Deleting an Element of an Array

QUESTION: How can I change the length of an array dynamically? For example, I need to delete an element from a array that has five elements and get a new array that has four elements.

ANSWER: Presumably, you know the index of the element you want to delete. There are three possibilities: (1) the index is 0, the first index in the array, (2) the index is the last index of the array, or (3) the index is something other than first or last index of the array.

So, you will use array subscripting to write code similar to this:

   first = 0
   last = N_Elements(array)-1
   CASE index OF
      first: array = array[1:*]
      last: array = array[first:last-1]
      ELSE: array = [ array[first:index-1], array[index+1:last] ]
   ENDCASE

Google
 
Web Coyote's Guide to IDL Programming