At the start of my program, I am declaring and filling 4 arrays that are used throughout the rest of the program:
var imageArrayGroup = [];
var floatingButtonArrayGroup = [];
for (i = 1; i < 3; i++) {
imageArrayGroup[i] = document.createElement("img");
imageArrayGroup[i].type = "image";
floatingButtonArrayGroup[i] = document.getElementById('floatingButton' + (100 + i));
floatingButtonArrayGroup[i].style.paddingLeft = "35px";
floatingButtonArrayGroup[i].style.paddingTop = "5px";
}
var imageArray = [];
var floatingButtonArray = [];
for (i = 1; i < 10; i++) {
imageArray[i] = document.createElement("img");
imageArray[i].type = "image";
floatingButtonArray[i] = document.getElementById('floatingButton' + (i));
floatingButtonArray[i].style.paddingLeft = "35px";
floatingButtonArray[i].style.paddingTop = "5px";
}
Later on in the code, I call a function that references the arrays.
function clearThumbnails() {
for (i = 1; i < 10; i++) {
if (floatingButtonArray[i].hasChildNodes())
floatingButtonArray[i].removeChild(imageArray[i]);
}
for (i = 1; i < 3; i++) {
if (floatingButtonArrayGroup[i].hasChildNodes())
floatingButtonArrayGroup[i].removeChild(imageArrayGroup[i]);
}
}
When running this function, I get the error "Uncaught TypeError: Cannot read property '1' of undefined"
Why is the variable undefined?
Complete code can be found at: http://codepen.io/angstd/pen/ropca Click on the word "Garage" to get the error message.