Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var newArray = [1, 2, 3, 4, 5]
- // filters callback function, takes two parameters,
- // element is the current element in the array.
- // index is the current index in the array
- newArray.filter(function (element, index) {
- // filter now loops through each element in the array, just like a for loop. Checking whether the current element passes the test below.
- return element > 3;
- });
- // newArray should now equal [4, 5]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement