Dictionary - Array Manipulation - Remove Index

FrameXX

Well-known member
I am actually curious if you can remove exact key or index from dict or array. For now you can always use the clear variable action to remove everything from variable.
 

Dm114

Well-known member
Thanx
But I want to remove the Array index
so there will be no Array[1] index.
Any ideas ?
Why don't you leave it with an empty value or any conventional value?

The only way to really remove items would be to:
1⁰- Copy every "valid" item from ArrayA to another empty array ArrayB (skipping the ones you want to remove)
2⁰- Clear ArrayA (Action: Clear variables) to remove all items
3⁰- Copy the whole ArrayB to ArrayA
4⁰- Clear ArrayB to spare space.

It's quite easy (and quick for arrays that are not too big).
 

Dm114

Well-known member
"Clear Variables" does that
You are partially right because Clear variable clears the whole array (removes all the items) but doesn't allow to remove them selectively.

When removing an item in a array, the array managing routines (here MacroDroid) have to reorganize the whole array to avoid "holes" in it. I guess @MacroDroidDev doesn't want to implement such a bit heavy feature for a low number of requests, as it is possible to write such a routine in our own macros/action blocks.
 

Dm114

Well-known member
Thanks guys for your 👍!

I don't know whether the guy who made the feature request (@Shaykid) even saw the answers... Never mind if it can help other members!

While I was thinking about this subject (removing indexes in an array) I realized that it could be a problem to have arrays with "holes" in index numbering (when removing one of them somewhere in the middle of the sequence) because outside the specific Loop action it's not possible to check whether an index exists or not if they are not in sequence...

So I made the Action block below:

Here are the comments:
INPUT variables:
ArrayIN => Your_array
IndexToRemove => the index you want to remove (don't forget to set its value otherwise index #0 will be removed)
FirstIndexUnchanged (optional) => to start numbering from the original first index. Default value=True
FirstNewIndex (optional) => the index # you want to start with (not taken into account if FistIndexUnchanged is True). Default value=0
OUTPUT variable:
ArrayOUT => Your_array (same as ArrayIN)
ℹ️ IndexToRemove refers to numbering BEFORE reorganization (the original one)

Let's say we have such an array with:
FirstIndexUnchanged=True
IndexToRemove=-3
ORIGINAL
(old index
array
old value)
||
||
NEW
(new index
array
new value)
-3value of -3||-3value of -1
-1value of -1||-2value of 1
1value of 1||-1value of 3
3value of 3||0value of 4
4value of 4||
 
Last edited:

FrameXX

Well-known member
Thanks guys for your 👍!

I don't know whether the guy who made the feature request (@Shaykid) even saw the answers... Never mind if it can help other members!

While I was thinking about this subject (removing indexes in an array) I realized that it could be a problem to have arrays with "holes" in index numbering (when removing one of them somewhere in the middle of the sequence) because outside the specific Loop action it's not possible to check whether an index exists or not if they are not in sequence...

So I made the Action block below:

Here are the comments:
INPUT variables:
ArrayIN => Your_array
IndexToRemove => the index you want to remove (don't forget to set its value otherwise index #0 will be removed)
FirstIndexUnchanged (optional) => to start numbering from the original first index. Default value=True
FirstNewIndex (optional) => the index # you want to start with (not taken into account if FistIndexUnchanged is True). Default value=0
OUTPUT variable:
ArrayOUT => Your_array (same as ArrayIN)
ℹ️ IndexToRemove refers to numbering BEFORE reorganization (the original one)

Let's say we have such an array with:
FirstIndexUnchanged=True
IndexToRemove=-3
ORIGINAL
(old index
array
old value)
||
||
NEW
(new index
array
new value)
-3value of -3||-3value of -1
-1value of -1||-2value of 1
1value of 1||-1value of 3
3value of 3||0value of 4
4value of 4||

This should have arleady been in the app. The way how MacroDroid deals with arrays is just broken. As @MacroDroidDev stated they are they are just tweaked dictionaries and it becames very striking and obvious when you try to use them.
 

dsnz

Well-known member
This should have arleady been in the app. The way how MacroDroid deals with arrays is just broken. As @MacroDroidDev stated they are they are just tweaked dictionaries and it becames very striking and obvious when you try to use them.
I wouldn't say that arrays are broken, they are just unusual
they are more like the arrays of the computer language Lua (famously used by Adobe Lightroom among others)
if you don't use negative indexes and you don't remove indexes then you have a nice classic array
if you do tricky things then you get tricky arrays 😂
I think it was a smart decision by @MacroDroidDev to standardize on a single base container , the dictionary
what he didn't anticipate though was that the MD users are smart too 😂 and want to do all the tricks ,
so some more functions related to arrays and dictionaries have to be added in the future (like the famous length, the remove element at an index of an array or remove element at a key of dictionary, join two dictionaries etc etc)
I'm sure there will be many such additions and we just have to wait 😊
 

Dm114

Well-known member
I wouldn't say that arrays are broken, they are just unusual
they are more like the arrays of the computer language Lua (famously used by Adobe Lightroom among others)
if you don't use negative indexes and you don't remove indexes then you have a nice classic array
if you do tricky things then you get tricky arrays 😂
I think it was a smart decision by @MacroDroidDev to standardize on a single base container , the dictionary
what he didn't anticipate though was that the MD users are smart too 😂 and want to do all the tricks ,
so some more functions related to arrays and dictionaries have to be added in the future (like the famous length, the remove element at an index of an array or remove element at a key of dictionary, join two dictionaries etc etc)
I'm sure there will be many such additions and we just have to wait 😊
I agree with you!

I don't know how MD could be called: at the very beginning it was not a language. Just a tool to automate some simple functions. Then, step by step, it became something very close to a language with all the enhancements and features added by @MacroDroidDev. It's more and more powerful and users want more and features... I'm not speaking about those deployed to correct a bug or a "weakness". No, I'm speaking about all these nice features (such as arrays or dictionaries) that now makes MD a powerful... "stuff"!

Hence, many of us will claim to get more and more features to facilitate our way of coding. Because now, thanks to MD we are coding! But I sometimes have the opportunity to make some of my friends remember that the device they/we are using (the mobile) is a... telephone. Not a computer! 🙂

And, from time to time, it's even not able to assume its original functions which are to make and get phone calls... 😉☹️
 

Kr99

New member
🙂
But I sometimes have the opportunity to make some of my friends remember that the device they/we are using (the mobile) is a... telephone. Not a computer!
Yeah just a telephone with more power than computers of the 1990s.

Make no mistake, we live in an age of pocket computers, cybernetics, and genetic experimentation. We call them phones, prosthetics, and medicine.

The myth is when people claim we have AI. It's really just advanced statistical modeling with evolutionary algorithms.
 
Top