Execute Feature Set

I am using a mixture of d3.js and jQuery to create visualizations. I have 3 functions that I try to put into an array and then execute one after the other, but I don’t think I’m doing it right, because when I click play, nothing happens. Here is my code:

var functionsArray = [oct12,oct13,oct14]; $('#play').click(function(){ for (var i = 0; i < functionsArray.length; i++){ functionsArray[i]; } 

I will raise jsfiddle soon ...

+4
source share
2 answers

You also need to call the function.

 functionsArray[i](); 
+6
source

use $.each

demonstration

 var functionsArray = [oct12,oct13,oct14]; $(functionsArray).each(function(key, val){ val(); }); function oct12(){ alert('oct12'); } function oct13(){ alert('oct13'); } function oct14(){ alert('oct14'); } 

+2
source

Source: https://habr.com/ru/post/1440745/


All Articles