Advertisement
Guest User

filter

a guest
May 27th, 2016
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.42 KB | None | 0 0
  1. var newArray = [1, 2, 3, 4, 5]
  2.  
  3. // filters callback function, takes two parameters,
  4. // element is the current element in the array.
  5. // index is the current index in the array
  6.  
  7. newArray.filter(function (element, index) {
  8. // filter now loops through each element in the array, just like a for loop. Checking whether the current element passes the test below.
  9. return element > 3;
  10. });
  11.  
  12. // newArray should now equal [4, 5]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement