Associative array/Creation: Difference between revisions

no edit summary
(Added zkl)
No edit summary
Line 1,111:
The in operator can be used to check whether an object has a property with a particular name:
<lang javascript>'foo' in assoc // true</lang>
 
=={{header|Julia}}==
We build dictionaries associating to some characters their code points, by listing the key/value pairs, through a dictionary comprehension, by creating an empty dictionary and filling it, finally by using the specific syntax associated to typed dictionaries.
<lang julia>julia> hash = {'a' => 97, 'b' => 98} # list keys/values
{'a'=>97,'b'=>98}
 
julia> hash = {c => int(c) for c = 'a':'d'} # dict comprehension
{'a'=>97,'c'=>99,'b'=>98,'d'=>100}
 
julia> hash['é'] = 233 ; hash # add an element
{'a'=>97,'c'=>99,'b'=>98,'é'=>233,'d'=>100}
 
julia> hash = Dict() # create an empty dict
Dict{Any,Any}()
 
julia> for c = 'a':'d' hash[c] = int(c) end ; hash # fill it
{'a'=>97,'c'=>99,'b'=>98,'d'=>100}
 
julia> hash = (Char=>Int64)['a' => 97, 'b' => 98] # create a typed dict
['a'=>97,'b'=>98]
 
julia> hash["a"] = 1 # type mismatch
ERROR: no method convert(Type{Char}, ASCIIString)
in setindex! at dict.jl:533</lang>
 
=={{header|K}}==