Associative array/Iteration: Difference between revisions

m (→‎{{header|Wren}}: Changed to Wren S/H)
 
(3 intermediate revisions by 3 users not shown)
Line 2,017:
 
=={{header|Kotlin}}==
<syntaxhighlight lang="scala">fun main(a: Array<String>) {
val map = mapOf("hello" to 1, "world" to 2, "!" to 3)
 
with(map) {
entries.forEach { println("key = ${it.key}, value = ${it.value}") }
keys.forEach { println("key = $it") }
values.forEach { println("value = $it") }
Line 4,139:
 
=={{header|Sidef}}==
<syntaxhighlight lang="ruby">var hash = Hash.new(
key1 => 'value1',
key2 => 'value2',
Line 4,146:
# Iterate over key-value pairs
hash.each { |key, value|
say "#{key}: #{value}";
}
 
# Iterate only over keys
hash.keys.each { |key|
say key;
}
 
# Iterate only over values
hash.values.each { |value|
say value;
}</syntaxhighlight>
{{out}}
Line 4,324:
 
=={{header|UNIX Shell}}==
TwoAt least two shells have associative arrays, but they use different syntax to access their keys.
 
{{works with|ksh93}}
{{works with|bash|4.0 and above}}
<syntaxhighlight lang="bash">typeset -A a=([key1]=value1 [key2]=value2)
 
1,934

edits