Using a variable to set array index number

Is it possible, and if yes, how, to use a variable to set array index position? For example:

varArray(“data[n].moredata”).ToString

Where “n” is a variable that can be dynamically set based on other conditions?

1 Like

Get rid of the quotes.

varArray(2)

is the same as…

assign myIndexInt = 2
varArray(myIndexInt)

Hey @dcurtis

Could you please explain what is the variable type for varArray and data here ?

Thanks
#nK

Hello @dcurtis

Are you trying to get some value from the array using the index?

if yes, then you can use as strArray[1].ToString,strArray[2].ToString, etc…

If requirement is something different plz give more insgiht

Yes, trying to get values from a JSON response from a service call. I want to be able to specify the index number of a response using a variable that is set previously in the execution.

1 Like

Could you please show your JSON data and highlight what you want to retrieve from it.

I’d like to be able to pull each “State” (in this example) as I iterate through and assign the value to a variable in a For Each loop. So, the first execution would return Alabama, next Alaska…

{
“data”: [{
“ID State”: “04000US01”,
“State”: “Alabama”,
“ID Year”: 2019,
“Year”: “2019”,
“Population”: 4903185,
“Slug State”: “alabama”
}, {
“ID State”: “04000US02”,
“State”: “Alaska”,
“ID Year”: 2019,
“Year”: “2019”,
“Population”: 731545,
“Slug State”: “alaska”
}, {
“ID State”: “04000US04”,
“State”: “Arizona”,
“ID Year”: 2019,
“Year”: “2019”,
“Population”: 7278717,
“Slug State”: “arizona”
}, {
“ID State”: “04000US05”,
“State”: “Arkansas”,
“ID Year”: 2019,
“Year”: “2019”,
“Population”: 3017804,
“Slug State”: “arkansas”
}, {
“ID State”: “04000US06”,
“State”: “California”,
“ID Year”: 2019,
“Year”: “2019”,
“Population”: 39512223,
“Slug State”: “california”
}, {
“ID State”: “04000US08”,
“State”: “Colorado”,
“ID Year”: 2019,
“Year”: “2019”,
“Population”: 5758736,
“Slug State”: “colorado”
}, {
“ID State”: “04000US09”,
“State”: “Connecticut”,
“ID Year”: 2019,
“Year”: “2019”,
“Population”: 3565287,
“Slug State”: “connecticut”

1 Like

Did you tried JArray ?