From a list of 1000 items, run a loop in batches of 100

Options

Hello,

I have a list of 1000 items and I have to run some functions for each one of them (on a loop) and finally upload all of them to an external database through an external api call.

The problem is this external database only allows to upload 100 items per api call so I can't wait until the 1000 loops are done and them upload all the items at once.

How can I upload them in batches of 100?

Tagged:

Best Answer

  • Pawel Magdanski
    Pawel Magdanski Member ✭✭✭
    Answer ✓
    Options

    Ok so I'm not sure if this is the best solution, but what you can do is create an empty array outside the loop to which you will append your processed item and then you are checking if the array have already 100 items, if not, then the loops just continues, if yes then you are uploading them, clearing the array and move on with loop.

Answers