Counter function in k6 similar to Jmeter function

Hi Team,
I would like to use the counter value for each post request and increment the number by 1. For example, I have a variable defined in my test script and I need to increment this number for each request by 1. Is it possible to achieve this in k6?


If you want to use it as a threshold metric you can get support from this

If you don’t want to write customized js code by yourself, you can also use this

But ofc this is a workaround, cuz this library is just created for Redis as a extension

Thanks for getting back to me. But it would be more helpful if i can get some example, as I’m really new to this. My requirement is to send a single post request multiple times. For each time I’m sending this post request, I’m trying to pass the number of the time in my payload variable is sent in order to fill my data in sequence.
Example in below payload, I’m trying to send the same payload but the customerId value should be incremented each time:
“customerId”: “0”,
“accountDetails”: {
“name”: “Test”,
“age”: “21”,
“gender”: “male”,
“mobileNumber”: “0123456789”