+ 1

don't execute when pass arguments in java-script function

function firstFunc(params) { console.log("first func",params) } var arr=[firstFunc(1),firstFunc(2),firstFunc(3),firstFunc(4)]//it execute here but I want it to execute after when I use arr.map(ele=>ele()}

11th Dec 2020, 4:39 PM
Juned Sheikh
Juned Sheikh - avatar
2 Réponses
+ 3
Instead of making a function array why not just use the arguments function firstFunc(params) { console.log("first func",params) } var arr=[1, 2, 3, 4] arr.map(ele=>firstFunc(ele))
11th Dec 2020, 5:59 PM
Toni Isotalo
Toni Isotalo - avatar
+ 1
#Toni Isotalo I am doing that thing:- -------------------------------- function firstFunc(params) { console.log("first func") } var arr=[firstFunc,firstFunc,firstFunc,firstFunc] var index=0 arr.forEach(element => { console.log(index++,":",element,) element() }); --------------------------------------------------------- and working fine. now I want it to run with argument if javascript have any option to do that
11th Dec 2020, 7:27 PM
Juned Sheikh
Juned Sheikh - avatar