For plain arrays (not associative arrays) empty check, I simply use:
if [[ -z ${array[@]} ]]; then
# do something
fi
EDIT:
If (and only if) the array certainly will never contain an empty 1st element, testing for only the first element would suffice, which might be faster for large arrays, but would require verification:
[[ -z $array ]] && ...
NOTE:
As already stated above, testing the array for size also works - which one's faster, would require verification, too.
BUT this test also works for arrays, which only contain one empty element and appears to be the safest method - for -z the test fails:
array=('')
[[ ${#array[@]} -eq 0 ]] && echo TRUE
[[ ${#array[@]} == 0 ]] && echo TRUE # as string compare
-> no output (OK)
[[ -z ${array[@]} ]] && echo TRUE
-> TRUE (FAIL)
A trick to work around the array single empty element issue with the -z test operator is to use @Q as expansion operator, since it outputs empty quotes - this also works for only checking the 1st array element:
[[ -z ${testA[@]@Q} ]] && echo TRUE
-> no output (OK)
[[ -z ${testA@Q} ]] && echo TRUE
-> no output (OK)
key=[]isn't an array; it's a regular variable with the value[]. Bash doesn't really have empty arrays: it has unset variables (which may or may not have the array attribute set), and it has array variables with one or more values assigned to them.