Vanilla JS Flashcards
Map (+ example)
The map() method creates a new array with the results of calling a provided function on every element in the calling array
const numbers = [2, 4, 8, 10]; const halves = numbers.map(x => x / 2); // halves is [1, 2, 4, 5]
Filter (+ example)
The filter() method creates a new array with all elements that pass the test implemented by the provided function.
const words = [“spray”, “limit”, “elite”, “exuberant”, “destruction”, “present”];
const longWords = words.filter(word => word.length > 6); // longWords is ["exuberant", "destruction", "present"]
Reduce (+ example)
The reduce() method applies a function against an accumulator and each element in the array (from left to right) to reduce it to a single value.
const total = [0, 1, 2, 3].reduce((sum, value) => sum + value, 1); // total is 7
Destructuring Assignment (+ example)
Assign the properties of an array or object to variables using syntax that looks similar to array or object literals
var first = someArray[0]; var second = someArray[1]; var third = someArray[2];
var [first, second, third] = someArray;
Declarative vs Imperative
…..