%dw 2.0
import * from dw::core::Arrays
output application/json
var users = ["Mariano", "Leandro", "Julian"]
---
indexOf(users, "Julian")
DataWeave
indexOf
indexOf<T>(array: Array<T>, toFind: T): Number
Returns the index of the first occurrence of an element within the array. If the value is not found, the function returns -1
.
Introduced in DataWeave version 2.2.0.
Parameters
Name | Description |
---|---|
|
The array of elements. |
|
The element to find. |
Example
This example returns the index of the matching value from the input array.
The index of "Julian"
is 2
.
Source
Output
2
json