class Hash
Description
A set of key/value pairs.
Hash can be thought of as an associative array, binding unique keys to
values (which are not necessarily unique), though it can not guarantee
consistent order its elements when iterating. Because of the nature of
JavaScript, every object is in fact a hash; but Hash adds a number of
methods that let you enumerate keys and values, iterate over key/value
pairs, merge two hashes together, and much more.
Creating a hash
There are two ways to construct a Hash instance: the first is regular
JavaScript object instantiation with the new keyword, and the second is
using the $H function. There is one difference between them: if a Hash
is passed to $H, it will be returned as-is, wherease the same hash passed
to new Hash will be cloned instead.
Related utilities
Methods
Constructor
new Hash([object])
Creates a new Hash. If object is given, the new hash will be populated
with all the object's properties. See $H.
Instance methods
-
clone
Hash#clone() -> HashReturns a clone of hash.
-
get
Hash#get(key) -> valueReturns the value of the hash’s
keyproperty. -
index
Hash#index(value) -> StringReturns the first key in the hash whose value matches
value. Returnsfalseif there is no such key. -
inspect
Hash#inspect() -> StringReturns the debug-oriented string representation of the hash.
-
keys
Hash#keys() -> [String...]Provides an Array of keys (that is, property names) for the hash.
-
merge
Hash#merge(object) -> HashReturns a new hash with
object's key/value pairs merged in. To modify the original hash in place, useHash#update. -
set
Hash#set(key, value) -> valueSets the hash’s
keyproperty tovalueand returnsvalue. -
toJSON
Hash#toJSON() -> StringReturns a JSON string.
-
toObject
Hash#toObject() -> ObjectReturns a cloned, vanilla object.
-
toQueryString
Hash#toQueryString() -> StringTurns a hash into its URL-encoded query string representation.
-
unset
Hash#unset(key) -> valueDeletes the hash’s
keyproperty and returns its value. -
update
Hash#update(object) -> HashUpdates hash with the key/value pairs of
object. The original hash will be modified. To return a new hash instead, useHash#merge. -
values
Hash#values() -> ArrayCollect the values of a hash and returns them in an array.
