Test4 (111)
A1: Array Push [ Name:%arr Position:10 Value:apple Fill Spaces:Off ]
A2: Array Push [ Name:%arr Position:10 Value:banana Fill Spaces:Off ]
A3: Array Push [ Name:%arr Position:10 Value:kiwi Fill Spaces:Off ]
A4: Variable Set [ Name:%arr To:%arr() Do Maths:Off Append:Off ]
A5: Variable Set [ Name:%find To:kiwi Do Maths:Off Append:Off ]
A6: JavaScriptlet [ Code:var arr=[arr];
var position = arr.indexOf(find); Libraries: Auto Exit:On Timeout (Seconds):10 ]
A7: Flash [ Text:%position Long:Off ]
This is my test profile, but %position always contains -1
Any help appreciated
> So I am trying to find the index of something in an array. Tasker doesn't have an action for this as far as I can tell, so I am trying to use a Javascriptlet to do this.
Many have missed this one... from the guide..
If the four variables %arr1, %arr2, %arr3, %arr4 hold respectively a, b, c and d then we have an array with 4 elements. These variables can be used just like any other,however it is also possible to access them in special ways. Here are some examples:
(4) %arr(#?b/c) A comma-separated list of the array indices (lowest to highest) with matching values,or 0 if none match (2,3 in the example)