Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Map array js - how to pass argument

Tags:

javascript

If I write map like this:

days=['m', 't'];
days.map(paste(day));

function paste(day) {
  alert(day)
}

It doesn't work;

How can i pass my argument day to function paste?

like image 938
user2950593 Avatar asked Jun 07 '26 18:06

user2950593


1 Answers

You need to pass your paste function to map, not invoke it:

var days = ['m', 't'];
days.map(paste);

function paste(day) {
  alert(day)
}

map function will iterate through the days array and invoke the function you passed in it on every object of the days.

like image 105
aga Avatar answered Jun 09 '26 08:06

aga



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!