Javascript passing array as parameter to function
问题 I have two function that accept an array as parameter, these function do a simple work, making all element of the array to zero. First function using forEach() method and passing a callback to it: function pass_arr(x) { x.forEach(function(y){ y = 0; }); } And I call it this way: var a = ["a", "b", 1, 3, "stringg"]; pass_arr(a); Then printing the content of array a: for(var i = 0; i < a.length; i++) { console.log(a[i]); } I execute this using node: #nodejs func.js and got the result a b 1 3