could not find this function in list-utils.sh
functionarray_indexof() {
[ $#-lt 2 ] &&return 1
local a=("$@")
local v="${a[-1]}"unset a[-1]
local i
foriin${!a[@]};doif [ "${a[$i]}"="$v" ];thenecho$ireturn 0 # stop after first matchfidonereturn 1
}
a=(1 2 3 4)
i=$(array_indexof "${a[@]}" 3)echo$i# 2also posted on https://stackoverflow.com/a/70793702/10440128
similar:
// javascript[1,2,3,4].indexOf(3)==2
# python
[1,2,3,4].index(3) ==2
could not find this function in
list-utils.shalso posted on https://stackoverflow.com/a/70793702/10440128
similar: