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 element
  • array 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

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c# - Copy ObservableCollection to another ObservableCollection -

All overlapping substrings matching a java regex -