Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript callbacks anonymous function

function filter(numbers, callback) {
  let results = [];
  for (const number of numbers) {
    if (callback(number)) {
      results.push(number);
    }
  }
  return results;
}

let numbers = [1, 2, 4, 7, 3, 5, 6];

let oddNumbers = filter(numbers, function (number) {
  return number % 2 != 0;
});

console.log(oddNumbers);
Code language: JavaScript (javascript)
Comment

PREVIOUS NEXT
Code Example
Javascript :: react native firebase login with facebook 
Javascript :: javaScript get() Method 
Javascript :: React Hook "useState" is called in function "app" which is neither a React function component or a custom React Hook function react-hooks/rules-of-hooks 
Javascript :: javascript log where function was called 
Javascript :: check if the collection exists in mongodb database mongoose 
Javascript :: jQuery exists function 
Javascript :: vuejs list items from axios 
Javascript :: if condition javascript 
Javascript :: react native bottom sheet above the bottom menu 
Javascript :: pre html 
Javascript :: get element attribute jquery 
Javascript :: react map array 
Javascript :: discord.js check every x minutes 
Javascript :: es6 spread assign nested object 
Javascript :: how to print json.stringify of nested objects 
Javascript :: swagger on expres node app 
Javascript :: Session Time Out 
Javascript :: usecallback in react 
Javascript :: jQuery Method Chaining 
Javascript :: write !important in react 
Javascript :: divide symbol to string in javascript 
Javascript :: js get elements in array from x to y 
Javascript :: (node:15855) UnhandledPromiseRejectionWarning: MongooseServerSelectionError: connect ECONNREFUSED 127.0.0.1:27017 
Javascript :: how to use brand icons in react 
Javascript :: google pay in react js 
Javascript :: open bootstrap modal using vanilla js 
Javascript :: How to filter data using javascript 
Javascript :: react native svg size 
Javascript :: set visible vue 
Javascript :: The Lodash Array Remove Method 
ADD CONTENT
Topic
Content
Source link
Name
9+5 =