JavaScript: How to pass extra parameters to a callback [duplicate]
问题 This question already has answers here : Pass an extra argument to a callback function (4 answers) Closed 3 years ago . I have a question which has bugged me for a while now. Let's say I have the following array: var array = [1, 2, 3] Now I have a function similar to this: function print(num, str) { console.log(str + ": " + num); } Is it possible to call the forEach method and pass a string to it? // how do I pass "str"? array.forEach(print); Thanks! 回答1: You have two options here: Either you