Looping through target variable | Community
Skip to main content
May 26, 2023
Solved

Looping through target variable

  • May 26, 2023
  • 2 replies
  • 932 views

Hi,

I have been trying to loop through a targetData variable using JSP.

In my workflow I have got 6 images. All of them are stored as below:

targetData.image1

targetData.image2

targetData.image3

targetData.image4

targetData.image5

targetData.image6

 

Instead of printing them separately, I want to run a loop and print it.

 

<% for(int i=0; i<6; i++) { %>

      <img src="<%= targetData.image[i] %>" />

<% } %>

 

I also tried

<% for(int i=0; i<6; i++) { %>

      <img src="<%= targetData.image.concat('i') %>" />

<% } %>

 

Nothing seems to work. Kindly help me with a solution.

 

 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by isahore

Hi @revathi05,

Try this inside the loop:

<img src="<%= eval('targetData.image' + i) %>" />

 

Let me know if it worked.

2 replies

isahore
Community Advisor
isahoreCommunity AdvisorAccepted solution
Community Advisor
May 26, 2023

Hi @revathi05,

Try this inside the loop:

<img src="<%= eval('targetData.image' + i) %>" />

 

Let me know if it worked.

Sukrity_Wadhwa
Community Manager
Community Manager
June 7, 2023

Hi @revathi05,

Was @isahore's solution helpful to resolve your query? In case it was helpful, then kindly choose it as the 'Correct Reply'. If not and you still need more help, then do let us know.

Sukrity Wadhwa