# Array search using arrayjobx

I'm using the arrayjobx to store data in arrays, and I want to search through those arrays.

For example, I might have a list of names and places and I want to search through those names to find the index of a given name in that array.

\newarray\Names
\newarray\Places


I want something like \findindex so that I can call the place associated to the person, e.g.

\Places(\findindex{\Names}{Bob})


should output Bangkok.

How might I do this?

• I'm not sure that arrayjobx is able to retrieve the index of an entry, without doing a loop over the whole array. Are you tied to arrayjobx or would you accept other solutions? – egreg May 21 '15 at 17:45
• I'd accept other solutions. Is there a good alternative to arrayjobx here? I did eventually figure out how to do a loop through the whole array to find the index, which solved my problem, though. – luftbahnfahrer May 22 '15 at 19:45

You probably want a property list, rather than two independent arrays.

\documentclass{article}
\usepackage{xparse}

\ExplSyntaxOn
{
\prop_gput:Nnn \g_luftbahn_person_place_plist { #1 } { #2 }
}

\DeclareExpandableDocumentCommand{\Place}{m}
{
\prop_item:Nn \g_luftbahn_person_place_plist { #1 }
}

\prop_new:N \g_luftbahn_person_place_plist
\ExplSyntaxOff