How to use the split function in js

  • 2020-03-30 01:07:34
  • OfStack

The split
A split, as opposed to a join, is used to split a string into an array of strings.
StringObject. Split (a,b), that's the syntax for it.

A is the necessary decision to split from a.
B is optional. This parameter specifies the maximum length of the returned array. If this parameter is set, no more substrings are returned than the array specified by this parameter. If this parameter is not set, the entire string is split.   Let's think about its length.

Note that the returned array does not include a itself;

Hints and comments
Comment: if an empty string ("") is used as a, then each character in stringObject is split.
Comment: string.split () does the opposite of what array.join does.

example
Var STR = "Hello World!" ;
Document. The write (STR. The split (" ") + "< Br / >" );
Document. The write (STR. The split (" ") + "< Br / >" );
Document. The write (STR. The split (" ", 3) + "< Br / >" );

return
H, e, l, l, o, W, o, r, l, d,!
Hello, World!
H, e, l


Related articles: