I am trying to set up an array of keys that are strings instead of numbers. But, when I try to do so, the array ends up null.
Here is the function that works (where the keys are just a simple number "i":
function loadImages(arr, data, callBack){
var count = 0;
var img = new Array();
for(var i in arr ){
var src = "\""+arr[i]+"\"";
img[i] = new Image();
img[i].src = arr[i];
img[i].onload = function(){
count++;
if(count == arr.length){
callBack(data, img);
}
}
}
}
Here is the function I am attempting to use but the resulting array is null:
function loadImages(arr, data, callBack){
var count = 0;
var img = new Array();
for(var i in arr ){
var src = "\""+arr[i]+"\"";
img[src] = new Image();
img[src].src = arr[i];
img[src].onload = function(){
count++;
if(count == arr.length){
callBack(data, img);
}
}
}
}
I have tried defining "src" in the following ways too:
var src = arr[i];
var src = "'"+arr[i]+"'";
Does anyone know why it is resulting in null?
{}. Arrays indices are numeric."\""+arr[i]+"\""looks very wrong. This will create a string which literally contains quotation marks (").