0

Code:

<% String r="4";
   String b="5;
%>
<script>
  var a={"red":"<%=r%>","blue":"<%=b%>"};
</script>

Is it possible to do like this and how to display those elements?

thor
  • 21,418
  • 31
  • 87
  • 173
Preethi
  • 45
  • 1
  • 8

1 Answers1

0

Yes you can do that, You can use hasOwnProperty to get key and value.

<% String r="4";
   String b="5";
%>
<script>
  var a={"red":"<%=r%>","blue":"<%=b%>"};
  for (var k in a){
       if (a.hasOwnProperty(k)) {
          alert("Key is :" + k + ", value is :" + a[k]);
       }
  }
</script>

You can make it as JS object if you use eval function. Hope this helps.

Vinoth Krishnan
  • 2,925
  • 6
  • 29
  • 34
  • Can you solve this problem.Here is the fiddle https://jsfiddle.net/tuc1faug/1/ Here the values are displayed in the cells .I want these values to be hidden.And I want to store it inside the array.How to do it? – Preethi Apr 05 '16 at 09:21
  • Yes always, Can you post this as a new question with your code and fiddle and what exactly you need.? – Vinoth Krishnan Apr 05 '16 at 09:26
  • See this http://stackoverflow.com/questions/36422413/hide-the-values-of-a-td-tag-using-jquery – Preethi Apr 05 '16 at 09:33