I am trying to pass an array that I have saved as a var. I declare the var in the parent function and add the arr as an argument in the parent function. Then I am pulling in the arr as an argument inside the callback invocation. The console tells me that linksA is undefined.
var supportLists = function(selector, arr) {
var parentList = document.getElementById(selector);
var theList = parentList.querySelectorAll("a");
var linksA = [
"http://www.example.com",
"http://www.example.com/path2",
"1",
"2",
"4",
"3",
"5",
"6",
"7"
];
var linksB = [
"1",
"2",
"3"
];
var linksC = [
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9",
"10",
"11",
"12"
];
var linksD = [
"1",
"2"
];
var linksE = [
"1",
"2",
"3"
];
var linksF = [
"1",
"2",
"3",
"4",
"5",
"6"
];
var linksG = [
"1",
"2",
"3"
];
var linksH = [
"1",
"2",
"3",
"4"
];
var linksI = [
"1"
];
var linksJ = [
"1",
"2",
"3",
"4",
"5"
];
function processLi(listItems, links) {
for (var i = 0; i < links.length; i++) {
listItems.forEach(function(item, index) {
item.href = links[index];
item.target = "_blank";
});
}
}
processLi(theList, arr);
};
supportLists("support-list", linksA);
supportLists("support-list-b", linksB);
supportLists("support-list-c", linksC);
supportLists("support-list-d", linksD);
supportLists("support-list-e", linksE);
supportLists("support-list-f", linksF);
supportLists("support-list-g", linksG);
supportLists("support-list-h", linksH);
supportLists("support-list-i", linksI);
supportLists("support-list-j", linksJ);