How, in Javascript, can I cast a string as an array in the same way that PHP (array) does.
//PHP
$array = (array)"string"
Basically I have a variable that can be an array or a string and, if a string, I want to make it an array using an inline command.
JavaScript is a prototyping language and does not have a type casting system.
One solution would be to check if your variable is a string and convert it into an array. For example :
In PHP, if you do a check on a string, like (ex:
$array = 'string';) :The JavaScript equivalent will be
If your variable
arris not necessarily a string, you may useinstanceof(edit: orArray.isArray) :