Developer forum
cancel
Showing results for 
Search instead for 
Did you mean: 

Removing an array key (with value)

dushyant
Booster
Hi

As a dictionary key can be removed using the function REMOVEKEY (dictionary.key), is there a way to remove an array's key (with value)?

I tried:
myDict.myArray[1] = 1
REMOVEKEY(myDict.myArray[1]) 
but that does not seem to remove it.

Thanks
2 REPLIES 2

runxel
Mentor
Sadly, there is no native way to delete/pop items from an array. This makes it necessary to do a bit of juggling.


dim arr[]
  arr[1] = 0.1
  arr[2] = 0.2
  arr[3] = 0.3

! index of the item you want to delete
todelete = 2

dim new_arr[]
check = 0
for i = 1 to vardim1(arr)-1
	if i = todelete then check = 1
	new_arr = arr[i+check]
next i

arr = new_arr

print arr   !>>> will print:  "0.1  0.3"
AC 24 [ger] | Win 10 | Developer of the GDL plugin for Sublime Text |
«Furthermore, I consider that Carth... yearly releases must be destroyed»

dushyant
Booster
Hi runxel

Ok, I get the idea. Thanks a lot!

Still looking?

Browse more topics

Back to forum

See latest solutions

Accepted solutions

Start a new discussion!