Getting item index from json array

Discuss macro implementations, ask for macro help (to share your creations, see User Creations, probably either Campaign Frameworks or Drop-in Resources).

Moderators: dorpond, trevor, Azhrei, giliath, jay, Mr.Ice

Post Reply
Templar
Cave Troll
Posts: 65
Joined: Wed Sep 20, 2017 9:24 pm

Getting item index from json array

Post by Templar »

Hi,

Hopefully this is simple.
If I have an array: testarray = ["bob", "fred", "ted", "Paul"]
I want to know the position in the array of "ted" (in this case its 2)

Is there a simple function that can give me that?
e.g. json.index(testarray , "ted"]

Of course I know json.index does not exist.

I know there are longer ways to do this (count through the array until I find "ted", but I thought there might be a function)?

Thanks
Templar

User avatar
aliasmask
RPTools Team
Posts: 9023
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: Getting item index from json array

Post by aliasmask »

I would bookmark this page of all the MapTool functions, https://wiki.rptools.info/index.php/Cat ... o_Function

What you're looking for is Wiki: json.indexOf().

Post Reply

Return to “Macros”