In this section, we'll explore mapping collections. Mapping one collection to another ranges from composing simple—as we saw in the preceding section—to sophisticated callbacks. Callbacks that map each item in the collection can include or exclude properties and can calculate new values. We'll also address the issue of filtering collections and how this can be done in conjunction with mapping.
When applied to an object, the pick()
function generates a new object containing only the specified properties. The opposite function, omit()
, generates an object with every property except those specified. Since these functions work fine for individual object instances, why not use them with a collection? You can use both of these functions to shed properties from collections by mapping them to new ones, as shown in the following code:
var collection = [ { first: 'Ryan', last: 'Coleman', age: 23 }, { first: 'Ann', last: 'Sutton', age: 31...