Home

# Library goog.object

Function Summary
| `add(?Object obj, string key, <Any Type> val)` Adds a key-value pair to the object. Throws an exception if the key is already in use. Use set if you want to change an existing pair.
| `clear(?Object obj)` Removes all key value pairs from the object/map/hash.
| `clone(?Object obj) ⇒ !Object` Does a flat clone of the object.
| `contains(?Object obj, <Any Type> val) ⇒ boolean` Whether the object/hash/map contains the given object as a value. An alias for goog.object.containsValue(obj, val).
| `containsKey(?Object obj, <Any Type> key) ⇒ boolean` Whether the object/map/hash contains the given key.
| `containsValue(?Object obj, <Any Type> val) ⇒ boolean` Whether the object/map/hash contains the given value. This is O(n).
| `create(<Any Type> var_args) ⇒ !Object` Creates a new object built from the key-value pairs provided as arguments.
| `createSet(<Any Type> var_args) ⇒ !Object` Creates a new object where the property names come from the arguments but the value is always set to true
| `every(?Object obj, ?Function f, ?Object= opt_obj) ⇒ boolean` Calls a function for each element in an object/map/hash. If all calls return true, returns true. If any call returns false, returns false at this point and does not continue to check the remaining elements.
| `extend(?Object target, (Object|null|undefined) var_args)` Extends an object with another object. This operates 'in-place'; it does not create a new Object. Example: var o = {}; goog.object.extend(o, {a: 0, b: 1}); o; // {a: 0, b: 1} goog.object.extend(o, {c: 2}); o; // {a: 0, b: 1, c: 2}
| `filter(?Object obj, ?Function f, ?Object= opt_obj) ⇒ !Object` Calls a function for each element in an object/map/hash. If that call returns true, adds the element to a new object.
| `findKey(?Object obj, function (*, string, (Object|null)): boolean f, ?Object= opt_this) ⇒ (string|undefined)` Searches an object for an element that satisfies the given condition and returns its key.
| `findValue(?Object obj, function (*, string, (Object|null)): boolean f, ?Object= opt_this) ⇒ <Any Type>` Searches an object for an element that satisfies the given condition and returns its value.
| `forEach(?Object obj, ?Function f, ?Object= opt_obj)` Calls a function for each element in an object/map/hash.
| `get(?Object obj, string key, <Any Type> opt_val) ⇒ <Any Type>` Returns the value for the given key.
| `getAnyKey(?Object obj) ⇒ (string|undefined)` Returns one key from the object map, if any exists. For map literals the returned key will be the first one in most of the browsers (a know exception is Konqueror).
| `getAnyValue(?Object obj) ⇒ <Any Type>` Returns one value from the object map, if any exists. For map literals the returned value will be the first one in most of the browsers (a know exception is Konqueror).
| `getCount(?Object obj) ⇒ number` Returns the number of key-value pairs in the object map.
| `getKeys(?Object obj) ⇒ !Array` Returns the keys of the object/map/hash.
| `getValueByKeys(!Object obj, (Array.<(number|string)>|number|string|undefined) var_args) ⇒ <Any Type>` Get a value from an object multiple levels deep. This is useful for pulling values from deeply nested objects, such as JSON responses. Example usage: getValueByKeys(jsonObj, 'foo', 'entries', 3)
| `getValues(?Object obj) ⇒ !Array` Returns the values of the object/map/hash.
| `isEmpty(?Object obj) ⇒ boolean` Whether the object/map/hash is empty.
| `map(?Object obj, ?Function f, ?Object= opt_obj) ⇒ !Object` For every element in an object/map/hash calls a function and inserts the result into a new object.
| `remove(?Object obj, <Any Type> key) ⇒ boolean` Removes a key-value pair based on the key.
| `set(?Object obj, string key, <Any Type> value)` Adds a key-value pair to the object/map/hash.
| `setIfUndefined(?Object obj, string key, <Any Type> value) ⇒ <Any Type>` Adds a key-value pair to the object/map/hash if it doesn't exist yet.
| `some(?Object obj, ?Function f, ?Object= opt_obj) ⇒ boolean` Calls a function for each element in an object/map/hash. If any call returns true, returns true (without checking the rest). If all calls return false, returns false.
| `transpose(?Object obj) ⇒ !Object` Returns a new object in which all the keys and values are interchanged (keys become values and values become keys). If multiple keys map to the same value, the chosen transposed value is implementation-dependent.

`unsafeClone(<Any Type> obj) ⇒ <Any Type>`

Clones a value. The input may be an Object, Array, or basic type. Objects and arrays will be cloned recursively. WARNINGS: `goog.object.unsafeClone` does not detect reference loops. Objects that refer to themselves will cause infinite recursion. `goog.object.unsafeClone` is unaware of unique identifiers, and copies UIDs created by `getUid` into cloned results.