Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

how to create my own filter in js

// filter takes an array and function as argumentfunction 
filter(arr, filterFunc) {
  const filterArr = []; // empty array        
  // loop though array    
  for(let i=0;i<arr.length;i++) {        
    const result = filterFunc(arr[i], i, arr);        
    // push the current element if result is true        
    if(result)             
      filterArr.push(arr[i]);     
  }    
  return filterArr;
}
Source by www.freecodecamp.org #
 
PREVIOUS NEXT
Tagged: #create #filter #js
ADD COMMENT
Topic
Name
9+7 =