Question

I would like to use a variable (string) as part of my JSON target. Instead of simply coding for each section, like this:

$.each(data.portfolioitems.section1, function (k,v){...}
$.each(data.portfolioitems.section2, function (k,v){...}
$.each(data.portfolioitems.section3, function (k,v){...}

I would like to have a variable "varsection" that indicates which section should be called, like this:

$.each(data.portfolioitems.varsection, function (k,v){...}

As this exists, it seems that I am attempting to target the section "varsection", which of course doesn't exist.

I have found other topics where it was discussed how to use a variable as part of a JSON target, but it seems that none of the solutions I found are acceptable for this scenario where the target is an argument.

Was it helpful?

Solution

data.portfolioitems[varsection]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top