Keep the array index of matching string

ofira85

New member
Hi All,

I would like to go over array I have already and look for all the cases in that array that have a match to a certain string ("name") and just keep all the index of of this match.

How can I do it with the actions i have in macrodroid ?

Thx, Ofir.
 

Endercraft

Moderator (& bug finder :D)
This should work.
Screenshot_2023-07-28-12-08-33-263-edit_com.arlosoft.macrodroid.jpg
Actually it won't work because you have to use != and not = in the constraint and also there's a known bug with deleting keys while iterating.
 

ofira85

New member
Hi,

Thank you for yor support.
In fact, when i try to set it exactly as did you show, the OK button is disable, why?

Attached photos FYR...
THX...
 

Attachments

  • Screenshot_20230728_132511_MacroDroid.jpg
    Screenshot_20230728_132511_MacroDroid.jpg
    620.3 KB · Views: 7
  • Screenshot_20230728_132454_MacroDroid.jpg
    Screenshot_20230728_132454_MacroDroid.jpg
    612 KB · Views: 7

Endercraft

Moderator (& bug finder :D)
Only use [[iterator_array_index]] in the field, the other text describes the other steps.
As I said it won't work but I already have a solution in mind..
 

Endercraft

Moderator (& bug finder :D)
Here's the working action block (don't forget to use the attached file).
Screenshot of used action block
 

Attachments

  • Delete_keys.macro
    8.9 KB · Views: 2

ofira85

New member
Thank you but it's still does not works or i miss something...

Attached video and photo....
 

Attachments

  • Screenshot_20230728_183526_MacroDroid.jpg
    Screenshot_20230728_183526_MacroDroid.jpg
    510.1 KB · Views: 8

Endercraft

Moderator (& bug finder :D)
Import the macro file.
In the action block configuration screen you can choose an array to delete keys, an output array and a string to keep.
 

ofira85

New member
I know, just release the body out....
I just don't sure how to input the array i had out of the block, i tried but without success...
 

ofira85

New member
Attached the file i try to works on....
By the way, the index could be change while the time and thats why i need to know the index
 

Dm114

Well-known member
Thank you but it's still does not works or i miss something...

Attached video and photo....
When using Clear array don't use Iterate loop because when an array element is cleared, indexes are not reordered. You must use a "classical" loop in the reverse order (from the highest index to 0) and Clear every current matching/non matching element.
 

ofira85

New member
I really thought it was supposed to be a simple process and there is a solution. Is there a lifeguard in the area ?
 

Endercraft

Moderator (& bug finder :D)
I don't fully understand what @Dm114 meant with the reverse loop but I understand that using normal loops won't cause any problems.

It seems you want something different from what I posted so can you describe exactly ?
 

ofira85

New member
I hope you can see my attachment (the array i try to work on)
Finally, i just want to release all the value/indexes which contein the string "name".
I want to store them in a new array and continue work on them.
Of course this array can be change and also the indexes vs the values.
And that's why I'm looking for a certain string in the array....
 

ofira85

New member
Any case you can't see my attachment
This is my array i try to work no:

[0]: {"20:00 - 05:00":[{"start":"2023-07-25T20:00:00"
[1]: "end":"2023-07-26T05:00:00"
[2]: "category":null
[3]: "position":"operator"
[4]: "description":""
[5]: "standbyType":0
[6]: "name":"Dean Shugert"
[7]: "image":"https://app.timetable.co.il:465/UsersProfilePic/UserPic_257399638216709978144825.png"}]
[8]: "22:00 - 07:00":[{"start":"2023-07-25T22:00:00"
[9]: "end":"2023-07-26T07:00:00"
[10]: "category":null
[11]: "position":"operator"
[12]: "description":""
[13]: "standbyType":0
[14]: "name":"Shay miser"
[15]: "image":null}]
[16]: "23:00 - 08:30":[{"start":"2023-07-25T23:00:00"
[17]: "end":"2023-07-26T08:30:00"
[18]: "category":null
[19]: "position":"operator"
[20]: "description":""
[21]: "standbyType":0
[22]: "name":"Shahar hurnet"
[23]: "image":null}]}
 

Dm114

Well-known member
I don't fully understand what @Dm114 meant with the reverse loop but I understand that using normal loops won't cause any problems.

It seems you want something different from what I posted so can you describe exactly ?
When iterating an array from index #0 to the last index # (dedicated Iteration loop or classical loop), Clear array action removes the the current array index but then skips next array index in the list (unless this bug has been fixed: I didn't check it recently).
 

Endercraft

Moderator (& bug finder :D)
[0]: {"20:00 - 05:00":[{"start":"2023-07-25T20:00:00"
[1]: "end":"2023-07-26T05:00:00"
[2]: "category":null
[3]: "position":"operator"
[4]: "description":""
[5]: "standbyType":0
[6]: "name":"Dean Shugert"
[7]: "image":"https://app.timetable.co.il:465/UsersProfilePic/UserPic_257399638216709978144825.png"}]
[8]: "22:00 - 07:00":[{"start":"2023-07-25T22:00:00"
[9]: "end":"2023-07-26T07:00:00"
[10]: "category":null
[11]: "position":"operator"
[12]: "description":""
[13]: "standbyType":0
[14]: "name":"Shay miser"
[15]: "image":null}]
[16]: "23:00 - 08:30":[{"start":"2023-07-25T23:00:00"
[17]: "end":"2023-07-26T08:30:00"
[18]: "category":null
[19]: "position":"operator"
[20]: "description":""
[21]: "standbyType":0
[22]: "name":"Shahar hurnet"
[23]: "image":null}]}
This is a dictionary. I'm not sure where you got the [0], [1], [2] and the others but you don't need them.
 

Endercraft

Moderator (& bug finder :D)
When iterating an array from index #0 to the last index # (dedicated Iteration loop or classical loop), Clear array action removes the the current array index but then skips next array index in the list (unless this bug has been fixed: I didn't check it recently).
It hasn't been fixed, that's why I saved the delete indexes into another array then deleted the indexes from the first array by iterating that second array.
 
Top