You can use the fact that string.toString () always returns the same string, and Array.toString () returns a comma-separated string in combination with string.split (',') to accept three possible inputs: convert a string, an array, a comma-delimited string reliably to an array (provided that you do not expect the commas to be part of the values โโthemselves, and you do not mind the numbers becoming strings).
In the simplest sense:
x.toString().split(',');
So,
'a' -> ['a'] ['a','b'] -> ['a','b'] 'a,b,c' -> ['a','b','c'] 1 -> ['1']
Ideally, you can wrap null, undefined, an empty string, an empty array (and still support a convenient one-liner):
( (x || x === 0 ) && ( x.length || x === parseFloat(x) ) ? x.toString().split(',') : []);
So also
null|undefined -> [] 0 -> ['0'] [] -> [] '' -> []
You can interpret the null / empty / undefined value differently, but for consistency, this method converts them to an empty array, so that the downstream code should not check the elements of array-having-elements (or, if iterating, checking is not required.)
This may not be very impressive if this is a limitation for you.
In your use:
var showRegion = function(key) { key = ( (key || key === 0 ) && ( key.length || key === parseFloat(key) ) ? key.toString().split(',') : []); }