JavaScript function arguments for filter function -
numbers = [1,2,3,4,5,4,3,2,1]; var filterresult = numbers.filter(function(i){ return (i > 2); });
i don't understand how works. if omit function argument breaks function isn't tied why need there?
.filter
(array.prototype.filter
) calls supplied function 3 arguments:
function(element, index, array) { ...
element
particular array element call.index
current index of elementarray
array being filtered.
you can use or of arguments.
in case, i
refers element
, used in body of function:
function(i){ return (i > 2); }
in other words, "filter elements element
greater 2".
Comments
Post a Comment