I'm trying to create variables using strings.
I'm writing a script that will load images from a array of strings and I want to store those images in variables with the name of the used string.
This is the code so far:
var images = ["CrazyWolf.jpg", "CrazyWolf.jpg", "CrazyWolf.jpg", "CrazyWolf.jpg"];
var name = "";
function preload(path)
{
img = new Image();
img.src = path;
img.onload = imageLoaded;
return img;
};
function makeImages()
{
for(var i = images.length; i > 0; i--)
{
source = images.shift();
preload(source);
var name = source.replace(".jpg", "Image");
console.log(name);
//make vars with as name, var name
//Console.log(name); returns: CrazyWolfImage
if(i==0) console.log("Loop ended");
}
}
How do I use this name to create variables out of it?
Any help would be greatly apreciated!
Thanks!
pathis defined in that exact code. What more definition would be needed?