Deleting elements out of an array

Matt Denton matt.denton at limelight.com.au
Thu Apr 18 09:46:01 EDT 2002


Hey back again.

Here's a tip on deleting elements from an array:

You might expect the following to delete "firstElement":

on mouseUp
   put 100 into myArray["firstElement"]
   put 200 into myArray["secondElement"]
   delete myArray["firstElement"]
   put the keys of myArray
end mouseUp

...however if you are not explicit, delete assumes a global array.  You 
need this:

on mouseUp
   put 100 into myArray["firstElement"]
   put 200 into myArray["secondElement"]
   delete local myArray["firstElement"]  # <-- local has been added
   put the keys of myArray
end mouseUp

A small snag that trapped me up tonight.  Useful to know anyway and not 
in docs.

Chow and good night.

M@

Matt Denton




More information about the use-livecode mailing list