December 2023
Intermediate to advanced
242 pages
5h 28m
English
The split() method splits a string into substrings and returns them as an array. The first argument, which can be either a string or a regex, specifies the position at which the split should occur. The second argument limits the number of elements returned in the array. Here’s an example:
| | const str = "a b c"; |
| | |
| | console.log(str.split(" ")); // → ["a", "b", "c"] |
| | console.log(str.split(/\s/, 2)); // → ["a", "b"] |
Indices | |
|---|---|
|
|
If you set the d flag in a regex, you’ll have access to the indices property in the result of exec(), match(), and matchAll(). For more on indices, see Recipe 40, Generating ... |
Read now
Unlock full access