Skip to content

Latest commit

 

History

History
47 lines (33 loc) · 830 Bytes

dw-arrays-functions-indexof.adoc

File metadata and controls

47 lines (33 loc) · 830 Bytes

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