Skip to content

#takeWhile

Returns the leading elements of an array that satisfy a condition.

#takeWhile(array, @x: predicate)
Category Arrays and sequencesValid in Property value
Name Type Description
array path | array The source array.
predicate lambda Returns true to keep taking.

array

source.json
{
"numbers": [ 1, 2, 6, 3 ]
}
transformer.json
{
"result": "#takeWhile($.numbers, @x: @x < 5)"
}
output.json
{
"result": [ 1, 2 ]
}

Try it in the playground →

#skipWhile · #take · #where