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.
Hacky, but works:
[].concat(arrayOrString);
//Usage:
[].concat("a");
//["a"]
[].concat(["a"]);
//["a"]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With