# Extract Variables in loop

This guide will help you to extract information from the API response of a test case having a loop and store the extracted information in an array.

# Use Case:

Suppose we have a test case to validate the Add contact API and we are executing this test case in a loop.

And we want to extract the contact ids of all the newly created contacts and we want to store them in an array say contactIds. Then we would like to delete those newly created contacts in the subsequent test case by using our variable contactIds.

# Steps:

  1. First extract the desired property say _id from the API response and store them in an array variable as shown in the image below:

Please note that the variable name contactIds[] must contain an empty array [] symbol in its name at the end. The empty array symbol tells the vREST NG application that the extracted value should be pushed in the variable contactIds. This step will store all the newly created contact ids in the variable contactIds.

  1. Now, we can use this contactIds variables in subsequent test case to delete those newly created contacts as shown in the image below:

In the above test case, we have specified the {{contactIds}} variable in the loop source property to iterate over the newly created contacts. And we have specified variable {{contactIds.$}} in the API endpoint to access individual array elements.