<indexOf>
<indexOf> is a General Operator
component that renders, for each value given by the target attribute, the position of the
first of its arguments equal to that value. Indices start at 1, and a target that does not
occur in the list gives 0. To find where a value belongs in a sorted list rather than
whether it is there at all, use <searchSorted>.
Attributes and Properties
Attributes for <indexOf>
Highlighted (3)
asListboolean. Default value: true. Whether to render the items separated by commas (true) or with no separator (false).
_componentListWithSelectableType. The value, or list of values, to look for.
typekeyword. Component type to interpret bare string children as. Omit it and they are read as what they look like: every piece naming a number makes the list numeric, anything else makes it text. Also decides how target is read, since it has no type of its own.
| Value | Description |
|---|---|
number | Read bare strings as numbers, ordered by value. |
math | Read bare strings as math expressions, ordered by value. |
text | Read bare strings as text, ordered alphabetically. |
boolean | Read bare strings as booleans, ordered with false before true. |
Other (5)
avoidScientificNotationWhether to render numbers in full decimal form rather than scientific notation.
displayDecimalsNumber of decimal places to display when rendering this number.
displayDigitsNumber of significant digits to display when rendering this number.
displaySmallAsZeroThreshold below which numbers are displayed as zero.
padZerosWhether to pad displayed numbers with trailing zeros to fill the requested digits/decimals.
Common to all components (9)
copyreference. Create an independent copy of another component by reference. Enter a references a $name.
disabledboolean. Default value: false. Whether this component is disabled and cannot be interacted with.
extendreference. Extend another component by reference, inheriting its children and attributes. Enter a reference as $name.
fixedDefault value: false. Whether this component's value is fixed and cannot be modified.
fixLocationboolean. Default value: false. Whether this component's location is fixed (preventing it from being moved while still allowing other modifications).
hideboolean. Default value: false. Whether to hide this component from the rendered output.
isResponseboolean. Default value: false. Whether this component is treated as a response for the purposes of assessment.
nametext. The name used to reference this component from elsewhere in the document.
styleNumberinteger. Default value: 1. The style number used to select this component's visual styling from the available style definitions.
Properties for <indexOf name="i">
Common to all components (4)
$i.doenetMLtext. The DoenetML source code that produced this component.
$i.hideboolean. Whether to hide this component from the rendered output.
$i.isResponseboolean. Whether this component is treated as a response for the purposes of assessment.
$i.styleNumberinteger. The style number used to select this component's visual styling from the available style definitions.
Examples
Example: finding a number
The value 20 occurs twice and the first occurrence is reported. A value that is absent gives 0, which is a position no list entry has.
Example: finding a name
type="text" tells <indexOf> to read the target as text rather than as a
number.
Example: looking up several targets at once
There is one result per target, in the order the targets were given. Eve is not on the roster, so her slot is 0 while the others keep their positions.
Example: looking up a parallel list
Finding a position in one list and reading it out of another is the usual reason to
want <indexOf> rather than a test for membership.
Attribute Examples
Attribute Example: target
target is read the way bare children are: whitespace separates one target from the
next, so target="New York" asks for two of them and neither is on the list. A value
with a space in it is written as a <text> of its own and referenced — which is
also how the list holding it is built, since <textList>Boston New York</textList>
is three cities and not two.