filter list of array if not true return default array 1

filter list of array if not true return default array

function isBigEnough(value) {
  return value >= 10;
}

var filtered = [12, 5, 8, 130, 44].filter(function(value) {
  return !isBigEnough(value);
});

console.log(filtered);

Here is what the above code is Doing:
1. We create a function called isBigEnough.
2. We create a variable called filtered and assign it to the result of calling the filter method on the array [12, 5, 8, 130, 44].
3. The filter method takes a callback function as an argument.
4. The callback function takes a value as an argument.
5. The callback function returns the result of calling the isBigEnough function with the value argument.
6. The filter method loops through each element in the array and passes the element to the callback function.
7. If the callback function returns true, the element gets pushed to the filtered array.
8. If the callback function returns false, the element does not get pushed to the filtered array.
9. The filter method returns the filtered array.
10. We log the filtered array to the console.

Similar Posts