Delete the first entry of an array.
Peter W A Wood
peterwawood at gmail.com
Fri Mar 25 03:33:15 EDT 2016
I have an array which contains a second array. (myArray[“numbers”][]). The numbers array is a traditional array with elements 1..n. I want to remove the first element of the numbers array and shuffle all the others up. Is there a simple way of doing this in LiveCode (equivalent to the shift() function in JavaScript)?
I looked in the dictionary and found delete <variable> but couldn't get it to work, perhaps because I am trying to do this in a function that takes the array as an argument.
The essence of the function is:
function shift @pList
local tItem
put pList[“numbers”][1] into tItem
delete pList[“numbers”] 1 ## Is this the correct syntax?
return tItem
end shift
If I can get delete to remove the first element of the array, will it automatically change the index of the remaining entries?
Thanks in advance.
Peter
More information about the use-livecode
mailing list