3

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?

2 Answers 2

4

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.

Sign up to request clarification or add additional context in comments.

1 Comment

ty just found it on mdn
0
days=['m', 't'];
days.map(function (a){paste(a)});

function paste(day) {
      alert(day)
}

This works but aga's is better. ( shorter).

However - notice cross platform issue http://jsbin.com/axaluq/42?q=array%20map

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.