Tap the arrow in the corner of the card to flip it!

array.filter()

  1. Takes an array
  2. A callback function filters the array
  3. Filter is applied to each array item
  4. If the value matches the filter (truthy), it's added to a new array
  5. If it doesn't match (falsy), ignore it
  6. Returns a new array

array.filter()

  • var fruits = ['pear', 'banana', 'plum'];
  • Fruits contains an array with 3 strings
  • const result = fruits.filter(fruit => fruit.length < 5);
  • Fruit represents each array item
  • console.log(result);
  • Values less than 5 characters are added to a new array and stored in result
  • // output: Array ['pear', 'plum']

Conditional Block

Code inside the conditional block will execute if the first statement is true

// The 'true' value 
// can be replaced 
// with another conditional
if (true) {
  // inner code executes
  // if the conditional 
  // is evaluates to true
}