I have an array of functions.
var arrOfFunc = [];
I have script that pushes to the array, a function that redraws a google chart
There can be multiple functions depending on how many graphs i decide to put on the page
var chart = "done";
function drawChart(){ ... } //each draw chart function belongs to its own scope.
arrOfFunc.push(drawChart);
$(window).resize(function(){
if(chart=="done"){
chart = "waiting";
setTimeout(function(){
for(var i in arrOfFunc ){
arrOfFunc[i]();
}
chart = "done"
},1000);
});
The problem is i have a refresh button for the grid that reruns the whole function that:
- makes the api call
- rerenders the grid with
drawChart() - than pushes the drawChart() function to arrOfFunc;
How can i check to see if the function already exists inside the array before deciding whether to push it to the arrOfFunc object?
Or does .indexOf() only work for strings.
indexOfworks for any data type.arrOfFunc.indexOf(drawChart) > -1drawGraphand give each graph anidthat you use to render it? LikedrawGraph(0); drawGraph(1); drawGraph(4324);