+ 13
How does the filter function work in js?
var c = newArray(1,2,3,4); var b = c.filter(function(a){return(a%2)}); alert(b[0]+b[1]) //the answer is 4
4 Respuestas
+ 10
ThanksTheWhiteCat 😍
+ 5
Filter method creates new array with elements that pass certain condition. In this case filter the even elements of the array. So b => [1, 3] and b[0]+b[1] is 4. You can find more info here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter. Hope it helps you.
+ 1
Tahir Usman , you are welcome 😉