Suppose there are arrays arr1 and arr2 . The first array contains numbers. It is necessary to rewrite it into the second array so that it contains functions. When calling arr2[3]() we get the same result as when calling arr1[3] . I implemented it like this:
var arrFunc = []; function convertArr(arr) { for (var i = 0; i < (arr.length - 1); i++) { arrFunc.push(function(x) { return arr[x] }(i)); } } But in this case it does not work correctly. You need to call arrFunc[3](3) .
arr2[3]()(a parameter is not passed to the function) orarrFunc[3](3)(a parameter is passed to the function, plus we assume thatarr2andarrFuncare the same thing)? - Regent