I'm trying to write a function that either accepts a list of strings, or a single string. If it's a string, then I want to convert it to an array with just the one item. Then I can loop over it without fear of an error.
So how do I check if the variable is an array?
I've rounded up the various solutions below and created a jsperf test.
转载于:https://stackoverflow.com/questions/4775722/check-if-object-is-an-array