Skip to content

Conformance Examples 0.1.0 — Transforms: transform-find_index

find_index-property-value

With two arguments, returns the index of the first struct whose property equals the value.

Template

{{ items | find_index: "k" "b" }}

Context

{
    "items": [
        {
            "k": "a"
        },
        {
            "k": "b"
        }
    ]
}

Output

1

find_index-property-truthy

With one argument, returns the index of the first struct whose property is truthy.

Template

{{ items | find_index: "ok" }}

Context

{
    "items": [
        {
            "ok": false
        },
        {
            "ok": true
        }
    ]
}

Output

1

find_index-no-match-is-null

When nothing matches, the result is null.

Template

{{ items | find_index: "k" "z" }}

Context

{
    "items": [
        {
            "k": "a"
        }
    ]
}

Output

null

find_index-non-list-is-null

find_index operates only on lists; a string input yields null.

Template

{{ x | find_index: "k" }}

Context

{
    "x": "hi"
}

Output

null

find_index-non-struct-contents-is-null

find_index expects a list of structs; non-struct contents yield null.

Template

{{ xs | find_index: "k" }}

Context

{
    "xs": [
        1
    ]
}

Output

null

Source fixture: transforms/transform-find_index.json