Selection and Transformation Flashcards
Selection is…
picking some elements out of a collection depending on one or more criteria. For example, you might want to pick out all the odd numbers from an array.
Transformation is…
manipulating every element in the collection.
A callback is
A function expression provided to another function/method as an argument
Object.keys(arr)
- will only show the keys of SET elements. will not include elements which are unset but technically in the array. However it will show the keys of non element properties
Array.Filter()
to perform the selection,filterexamines the return value of the callback on each iteration. It determines thetruthinessof the return value. There’s only one thing thatfiltercares about concerning the callback’s return value: whether it istruthyorfalsy. Note that truthy and falsy are not the same astrueandfalse.
Array.prototype.find
The find method also takes a callback function as an argument and returns the first element for which the callback function returns a truthy value:
Array.prototype.findIndex
findIndex is similar to find except it returns the index of the element for which the callback returns a truthy value: