I have a JavaScript function, similar to
function ColorListPicker(listLength) {
var colorCodeArray = ["#046c93", "#4caf50", "#8bc34a", "#cddc39", "#00bcd4", "#009688", "#e91e63", "#673ab7", "#ff9800", "#9e9e9e", "#f3f3f3"];
var colorList = "[";
for (var i = 0; i < listLength; i++) {
colorList = colorList + '"' + colorCodeArray[i] + '",';
}
var colorListData = colorList.substr(0, colorList.length – 1);
colorListData = colorListData + "]";
return colorListData;
}
If I call this function normally, like var colorList = ColorListPicker(5);
, then the colorList
variable is set to the return value, as though I had done colorList=["#046c93", "#4caf50", "#8bc34a", "#cddc39", "#00bcd4"]
.
But I want to declare colorCodeArray
to be a global and use it from my ColorListPicker
function.
How can I make ColorListPicker
set a global variable, instead of returning a value?