$$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​
Argument | Type | Values | Required / Default Value | Description |
---|---|---|---|---|
Primary | array | Yes | Array of elements | |
by | Transformer(##current ,##index ) | ##current | A predicate transformer for an element
|
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