Skip to main content

$$findindex

Find the index of the first element in a specified array that satisfy the predicate transformer.

If none of the elements satisfy the predicate the result will be -1.

Usage​

{ 
"$$findindex": /* Array of elements */,
"by": "##current" /* Transformer(##current,##index) */
}
"$$findindex([by]):{input}"
note

Concrete values in the usage example are default values.

info

predicate by should resolve to a boolean value, it uses the truthy logic

Returns​

number

Arguments​

ArgumentTypeValuesRequired / Default ValueDescription
PrimaryarrayYesArray of elements
byTransformer(##current,##index)##currentA predicate transformer for an element
  • ##current - Current element
  • ##index - Current index

Examples​

Input

Definition

Output

[
0,
[],
"a"
]
{
"$$findindex": "$",
"by": "##current"
}
2
[
"a",
"1",
"true"
]
{
"$$findindex": "$",
"by": "$$boolean:##current"
}
2
[
"a",
"1",
"false"
]
{
"$$findindex": "$",
"by": "$$boolean:##current"
}
-1
[
0,
[],
"a"
]
"$$findindex(##current):$"
2
[
0,
[],
"false"
]
"$$findindex('$$boolean:##current'):$"
-1