using eval to get a function

use an array and object notation to dynamically reference a function you know exists at the time you make the call but not at the time you obtained the array. sequence: 1. array is given. can't "eval" because it would be undefined 2. js containing a function is loaded 3. "eval" the array which references script from step 2

by Gerald Gillespie

HTML

<script src="https://support.kace.com/jkuery/www/js/jqplot/dist/jquery.jqplot.min.js"></script>
<script src="https://support.kace.com/jkuery/www/js/jqplot/dist/plugins/jqplot.barRenderer.min.js"></script>
<h3>JSON String</h3>
<div></div>
<br /><br />
<h3>JSON Object</h3>
<div></div>

JavaScript

var primaryR = ['jqplot','BarRenderer'];

alert('hi');
var primaryRenderer = $[primaryR[0]][primaryR[1]];

var otherthing=$;
for(var i =0; i < primaryR.length; i++){
  console.log(otherthing);
  otherthing = otherthing[primaryR[i]];

}	// end for
				
  console.log(otherthing);

$('div:first').html(primaryRenderer.toString());

$('div:last').html(otherthing.toString());