%dw 2.0
output application/json
---
{
present: ["a","b","c","d"] lastIndexOf "c",
notPresent: ["x","w","x"] lastIndexOf "c",
presentMoreThanOnce: ["a","b","c","c"] lastIndexOf "c",
}
DataWeave
lastIndexOf
lastIndexOf(array: Array, value: Any): Number
Returns the index of the last occurrence of the specified element in a given
array or -1
if the array does not contain the element.
Introduced in DataWeave version 2.4.0.
Parameters
Name | Description |
---|---|
|
The array of elements to search. |
|
The value to search. |
Example
This example shows how indexOf
behaves given different inputs.
Source
Output
{
"present": 2,
"notPresent": -1,
"presentMoreThanOnce": 3
}
Json
lastIndexOf(array: String, value: String): Number
Takes a string as input and returns the index of the last occurrence of
a given search string within the input. The function returns -1
if the
search string is not present in the input.
Introduced in DataWeave version 2.4.0.
Parameters
Name | Description |
---|---|
|
The string to search. |
|
A string value to search for within the input string. |
Example
This example shows how the indexOf
behaves given different inputs.
Source
%dw 2.0
output application/json
---
{
present: "abcd" lastIndexOf "c",
notPresent: "xyz" lastIndexOf "c",
presentMoreThanOnce: "abcdc" lastIndexOf "c",
}
DataWeave
Output
{
"present": 2,
"notPresent": -1,
"presentMoreThanOnce": 4
}
Json
lastIndexOf(array: Null, value: Any): Number
Helper function that enables lastIndexOf
to work with a null
value.
Introduced in DataWeave version 2.4.0.