<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. |
Number display (5)
avoidScientificNotationboolean. Default value: false. Whether to render numbers in full decimal form rather than scientific notation.
displayDecimalsinteger. Default value: 2. Number of decimal places to display when rendering this number.
displayDigitsinteger. Default value: 3. Number of significant digits to display when rendering this number.
displaySmallAsZeronumber. Default value: 1e-14. Threshold below which numbers are displayed as zero.
padZerosboolean. Default value: false. Whether 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.
fixedboolean. Default 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">
Number display (5)
$i.avoidScientificNotationIn developmentboolean. Whether to render numbers in full decimal form rather than scientific notation.
$i.displayDecimalsIn developmentinteger. Number of decimal places to display when rendering this number.
$i.displayDigitsIn developmentinteger. Number of significant digits to display when rendering this number.
$i.displaySmallAsZeroIn developmentnumber. Threshold below which numbers are displayed as zero.
$i.padZerosIn developmentboolean. Whether to pad displayed numbers with trailing zeros to fill the requested digits/decimals.
Common to all components (8)
$i.disabledIn developmentboolean. Whether this component is disabled and cannot be interacted with.
$i.doenetMLtext. The DoenetML source code that produced this component.
$i.fixedIn developmentboolean. Whether this component's value is fixed and cannot be modified.
$i.fixLocationIn developmentboolean. Whether this component's location is fixed (preventing it from being moved while still allowing other modifications).
$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.
Example: indexing without naming the lookup
The <indexOf> can be written between the index brackets instead of being named
and referenced. Both find the same position, so which to use is a matter of how the
sentence reads: naming it keeps a long index out of the prose, and is what to do when
the same position is wanted more than once.
A property can follow the brackets, as the second paragraph shows, and so can a further index.
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.