Per the other answers this is the difference between associative (key=value pairs) and indexed (index 0-infinity, value) arrays in Bash.
Now if you want to do a clever trick by building up an indexed array and converting it to an associative array later this is possible, though keep in mind the "values" that get converted to "keys" must be unique in the array or they will get overwritten unless you do some tracking of how many times a given "value" was seen and insert the indices into an array of values for each "key".
https://unix.stackexchange.com/a/177589
declare -a array1
array1=() # Empty the array to avoid repeated runs introducing side effects
# Using `+=($stuff)` adds to an array, using `+=$stuff` concatenates text
# if $stuff might have spaces, double quote it! or just always quote!
# see the tricky 'bar baz' with a space
for eachword in foo 'bar baz' fizzbuzz; do array1+=("$eachword"); done
# Make SURE you quote the array when looping over in case values have spaces
for eachword in "${array1[@]}"; do echo "$eachword"; done
declare -A map # required: declare explicit associative array
for key in "${!array1[@]}" # expand the array indexes to a list of words
do
# Check uniqueness note
map[${array1[$key]}]="$key" # exchange the value ${array1[$key]} with the index $key
done
# Debug printing the new associative array
for eachkey in "${!map[@]}"; do echo "${eachkey}"; done
for eachvalue in "${map[@]}"; do echo "${eachvalue}"; done
a=fizzbuzz
[[ -n "${map[$a]}" ]] && printf '%s is in array\n' "$a"
# UNIQUENESS NOTE
# Add code before the map if you won't have unique "keys"
# It should check if the $array1[$key] already exists and make its "value" an array where you append every new index where it existed
# NOTE: there may be some limitations with nested arrays in Bash