Is not a bug on RouterOS, you must understand the differencies between one string and one number.
“$testIdx” is a redundancy for $testIdx only without quotes, so all “$testIdx” is converted with $testIdx value, 2 as number.
using :tostr you force convert $testIdx before is used as variable.
The question is what happens once the 2 is transformed into a string and assigned to the array WITHOUT double quotes.
In other words a 2 as string is a string with or without quotes, 2 as a number may become a string when surrounded by quotes, but it may also remain a number, notwithstanding the quotes.
For example, 1 can be 1 as a number, “1” as a string and… 1 as true… 1 as array, 1 as time… etc. etc. etc.
It all depends on the context and how badly the script was written
:if (1) do={:put “true”} ; # NOTE: is not like (1 = true)…
true
:local x 1 ; :put [:typeof $x]
num
:local x “1” ; :put [:typeof $x]
str
:local x [:toarray 1] ; :put [:typeof $x] ; put $x