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

array

The array of elements.

toFind

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

%dw 2.0
import * from dw::core::Arrays
output application/json
var users = ["Mariano", "Leandro", "Julian"]
---
indexOf(users, "Julian")

Output

2

Was this article helpful?

💙 Thanks for your feedback!

Edit on GitHub