Home > OS >  Karate: How to get first N elements from a list?
Karate: How to get first N elements from a list?

Time:10-14

the response is a list of strings, like below:

[abc, def, ghi ...]

I want to get only the first 10 elements/indexes from this list/array.

can we use something like below?

 * def result = response[0-9]

is there any other way of doing it, I know the above code will fail.

CodePudding user response:

Just use the JS Array.slice():

* def nums = [1, 2, 3, 4, 5]
* def some = nums.slice(0, 3)
* match some == [1, 2, 3]
  • Related