Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

array.filter

// let arr = [1,2,3]

/*
  filter accepts a callback function, and each value of arr is passed to the 
  callback function. You define the callback function as you would a regular
  function, you're just doing it inside the filter function. filter applies the code 
  in the callback function to each value of arr, and creates a new array based on your 
  callback functions return values. The return value must be a boolean, which denotes whether an element 
  should be keep or not
*/
let filteredArr = arr.filter(function(value){
	return value >= 2
})

// filteredArr is:
// [2,3]
Source by www.javascripttutorial.net #
 
PREVIOUS NEXT
Tagged:
ADD COMMENT
Topic
Name
6+3 =