How to turn a single word in the input field into an array?

Hi,

I know that we can split() a string into an array, if we have a string in an input field like this, “javascript rocks”

what if there is only one keyword in the input field?

for instance, it is only a word - “javascript”?

thanks,
Lau

You can still split it. If the delimiter is not found, the result is an array with a single element.

But, if this is something that you simply would never actually want to split by some delimiter, just do var arr = [str];

got it! thank you very much :smiley: