Click here to Skip to main content
15,890,043 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
hi,

i want to create some dynamic variable Name at run time. let have an example like

below,

function example()
{
 var actualLng=new google.maps.Polyline(polylineoptns);
}


What I have tried:

now the example method i will iterate multiple time .while i am doing this scenarios i have to change the variable name like actualLng1,actualLng2,actualLng3.....
Posted
Updated 28-Dec-17 2:23am

1 solution

try something like this

function example(count) {
          this["actualLng" + i] = 'something ' + i;
      }

      for (var i = 0; i < 5; i++) {
          example(i);
      }

      console.log(actualLng0)  //something 0
      console.log(actualLng1)  //something 1
      console.log(actualLng2)  //something 2
      console.log(actualLng3)  //something 3
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900