For a simple function, how can I return an array with a string as a parameter? I want the array to split the string at the spaces so it returns as [" ", " "]
.
I tried using the split method split(" ", 2)
but it didn't seem to work.
var arr = str.split(" ");
You don't need to add 2 after.
The 2 limit the number of value in the array, if you want to split the string without a max, then take out the 2.
The split will "split" the string with " ", if you want to split with other character, replace the space by what you need.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.