rekey()

Modifies keys of an object or augments the object with more keys for the same values.

This function is valid in v2.19.0 to v2.23.0. This function has been downloaded 11 times.

Parameters

{Array|Object} obj
The object or array to be cloned, possibly augmented and changed. If not given then a partial function will be returned by rekey().
{Array|Object} keyMap
Specifies how to update the clone of obj. If this is an object the keys will correspond to the current keys and values will correspond to the new keys. If this is an array then each value must be an array where the first item is used to match current keys and the second item is used to define the new keys. An array at times may be preferred so that you can target one or more current keys using a function (which is passed just passed each current key and should return a value indicating whether it should be modified) or a regular expression. If the property values or each array item's second value is a function, it will be called with the value of the current key that is to be modified or augmented and the return value will be used as the new key or additional key.
{boolean=} opt_keepOriginals Optional, Default:false
If true then the returned object or array will be an augmented version of obj. Otherwise any keys that are found in obj because of keyMap values will simply be replaced according to the corresponding values in keyMap.

Returns

{Function|Array|Object}
If obj is undefined or null a partial function which will allow for obj to be defined will be returned. If obj is array-like a new array will be returned. Otherwise a new object will be returned. In the case that an array or an object is returned the keys will be based on the keys from obj and the values determined by keyMap.

Required Functions

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

  • 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.
  • isArrayLike()
    Determines if an object is an array or at least array-like.