What happens if you do this instead?:
if(temp.indexOf(",") >= 0)
I know I've had cases where it seemed to not understand what the object type was when reference from an array instead of a variable created from the contents of that array location. It doesn't make sense that this would be the case, but I've used it as a workaround before.