Using Array object as variable name

I am looping through a large array and the value in one of the array objects will be the name of another variable on the page. I need to be able to write the array object but have the value processed as a variable name to pull the variables value.

Is this possible? If so how would I go about accomplishing it?
 
var Date17000 = "Jan 2014"
var Date23000 = "Feb 2014"




var projectsArray =

[


 { "Fund": "Project A",

  "Designation": "17000",

  "YearDes": Date17000,

  "Title": "General",

  "AmountAsked": "0.00",

  "UpdateSent": "",

   },
 { "Fund": "Project B",

  "Designation": "23000",

  "YearDes": Date23000,

  "Title": "Restricted",

  "AmountAsked": "460.00",

  "UpdateSent": "",

   }
   ]
   
   
   
   for(var i=0;i<projectsArray.length;i++) {

    var obj = projectsArray[i];
	
	
if (obj.YearDes == "Jan 2014") { var Jan2014 = Jan2014 + 1;
  }
else if (obj.YearDes == "Feb 2014") { var Feb2014 = Feb2014 + 1;}
}

Open in new window

turtleman2009Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Robert SchuttSoftware EngineerCommented:
Your end goal is not entirely clear to me but the bit at the end there seems to suggest you just want to count all occurrences of months in the projects array. This may just do what you want:
  var arrCount = new Array();
  for(var i=0;i<projectsArray.length;i++) {
    var obj = projectsArray[i];
    if (!arrCount[obj.YearDes]) {
      arrCount[obj.YearDes]=0;
    }
    arrCount[obj.YearDes]++;
  }

  // show specific result
  alert(arrCount[Date17000]);

  // show all results in an alert
  var msg = "";
  for(var yr in arrCount) {
    msg += yr + ": " + arrCount[yr] + "\n";
  }
  alert(msg);

Open in new window

0
turtleman2009Author Commented:
I probably didn't explain it well. Sorry about that.

The problem is I have an array that has all the information for individual product entries, the only thing it does not have included is the date. The dates are exported into another file as variables. But I need to be able associate each array entry with it's appropriate date from the list of variables so I can produce monthly and yearly reports about the amount of items as well as combined profit from each type of item.
0
Robert SchuttSoftware EngineerCommented:
Ok, I'm afraid in that case it's still not clear to me what you need to find and where you need to put it.

Are you aware that the Datexxx variables are not actually put in the array, but their values are?

Here are some alerts to show how you can combine info in the projects array to see what's in there, maybe it helps you to find or at least describe what you actually need to do.
  alert(projectsArray[0]["Fund"]);                       // => Project A
  alert(projectsArray[0]["Designation"]);                // => 17000
  alert(window["Date"+projectsArray[0]["Designation"]]); // => Jan 2014
  alert(projectsArray[0]["YearDes"]);                    // => Jan 2014

Open in new window

0
turtleman2009Author Commented:
I ended up fixing my issues a different way.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
turtleman2009Author Commented:
Thanks for your help
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.