flatMap()

Iterates through each item in an array or an object, passing the item to a mapping function, and flattens the result into the array or object.

This function is valid in v2.13.0 to v2.24.3. This function has been downloaded 60 times.

Parameters

{Array|Object} arrOrObj
Array or object whose items should be iterated through and passed to the mapping function.
{Function} mapper
Mapping function which will be passed (1) the item be analyzed, (2) the corresponding index or key for said item, and (3) a reference to arrOrObj. The return value will be flattened into the array or object returned from flatMap().
{*=} opt_thisArg Optional
The value that will be referenced when using the this keyword within mapper. If not given this will refer to the global object.

Returns

{Array|Object}
If arrOrObj was an array then an array will be returned, otherwise an object will be returned. If an array, the values returned from mapper for each item will occupy the position of the original item in this new array. If an object, the values returned from mapper will be used instead of the items that were passed in and the new object will use the key(s) from the objects returned for this new object.

Required Functions

This function directly requires the following functions which are included automatically:

  • extend()
    Adds extra properties to an object based on the properties owned by other specified objects.
  • has()
    Every object descended from Object inherits the hasOwnProperty method. This method can be used to determine whether an object has the specified property as a direct property of that object; unlike the in operator, this method does not check down the object's prototype chain.