goog.object
Namespace.add(obj, key, 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.
obj
{Object
}
key
{string
}
val
{*}
.clear(obj)
Removes all key value pairs from the object/map/hash.
obj
{Object
}
.clone(obj)
Does a flat clone of the object.
obj
{Object
}
Object
}
.contains(obj, val)
Whether the object/hash/map contains the given object as a value. An alias for goog.object.containsValue(obj, val).
obj
{Object
}
val
{*}
boolean
}
.containsKey(obj, key)
Whether the object/map/hash contains the given key.
obj
{Object
}
key
{*}
boolean
}
.containsValue(obj, val)
Whether the object/map/hash contains the given value. This is O(n).
obj
{Object
}
val
{*}
boolean
}
.create(var_args)
Creates a new object built from the key-value pairs provided as arguments.
var_args
{...*}
Object
}
.createImmutableView(obj)
Creates an immutable view of the underlying object, if the browser supports immutable objects. In default mode, writes to this view will fail silently. In strict mode, they will throw an error.
obj
{!Object
}
Object
}
.createSet(var_args)
Creates a new object where the property names come from the arguments but the value is always set to true
var_args
{...*}
Object
}
.every(obj, f, opt_obj)
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.
obj
{Object
}
f
{Function
}
opt_obj
{Object
=}
boolean
}
.extend(target, 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}
target
{Object
}
var_args
{...Object
}
.filter(obj, f, opt_obj)
Calls a function for each element in an object/map/hash. If that call returns true, adds the element to a new object.
obj
{Object
}
f
{Function
}
opt_obj
{Object
=}
Object
}
.findKey(obj, f, opt_this)
Searches an object for an element that satisfies the given condition and returns its key.
obj
{Object
}
f
{function
(*, string
, Object
): boolean
}
opt_this
{Object
=}
string
|undefined
}
.findValue(obj, f, opt_this)
Searches an object for an element that satisfies the given condition and returns its value.
obj
{Object
}
f
{function
(*, string
, Object
): boolean
}
opt_this
{Object
=}
.forEach(obj, f, opt_obj)
Calls a function for each element in an object/map/hash.
obj
{Object
}
f
{Function
}
opt_obj
{Object
=}
.get(obj, key, opt_val)
Returns the value for the given key.
obj
{Object
}
key
{string
}
opt_val
{*=}
.getAnyKey(obj)
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).
obj
{Object
}
string
|undefined
}
.getAnyValue(obj)
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).
obj
{Object
}
.getCount(obj)
Returns the number of key-value pairs in the object map.
obj
{Object
}
number
}
.getKeys(obj)
Returns the keys of the object/map/hash.
obj
{Object
}
Array
.<string
>}
.getValueByKeys(obj, var_args)
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)
obj
{!Object
}
var_args
{...(string
|number
|!Array
.<number
|string
>)}
.getValues(obj)
Returns the values of the object/map/hash.
obj
{Object
}
Array
}
.isEmpty(obj)
Whether the object/map/hash is empty.
obj
{Object
}
boolean
}
.isImmutableView(obj)
obj
{!Object
}
boolean
}
.map(obj, f, opt_obj)
For every element in an object/map/hash calls a function and inserts the result into a new object.
obj
{Object
}
f
{Function
}
opt_obj
{Object
=}
Object
}
.remove(obj, key)
Removes a key-value pair based on the key.
obj
{Object
}
key
{*}
boolean
}
.set(obj, key, value)
Adds a key-value pair to the object/map/hash.
obj
{Object
}
key
{string
}
value
{*}
.setIfUndefined(obj, key, value)
Adds a key-value pair to the object/map/hash if it doesn't exist yet.
obj
{Object
}
key
{string
}
value
{*}
.some(obj, f, opt_obj)
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.
obj
{Object
}
f
{Function
}
opt_obj
{Object
=}
boolean
}
.transpose(obj)
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.
obj
{Object
}
Object
}
.unsafeClone(obj)
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.
obj
{*}