Search code examples
jsonata

How to get index of element in array in JSONata


JSONata provides several functions to operate on array contents. However, I am at a loss to determine how to return the index of a found element (similar to the Array.indexOf function in JavaScript). I'm looking for something like:

$indexOf(Account.Order[OrderID="order103"])
or
Account.Order.indexOf(OrderID="order103")
or
Account.Order[OrderID="order103"].index

Solution

  • Try this:

    Account.Order ~> $map(function($v, $i) { $v.OrderID = 'order103' ? $i })