JAVASCRIPT - HOW TO Split a Split to Return Multiple Substrings - Javascript Source Code

JAVASCRIPT - HOW TO Split a String, and Then Split Each Array Item to Return Multiple Substrings.

Home Short:

If you have a string where you wish to extract multiple substrings from it, you can use a special double split trick. An example of where this might be useful in Javascript, lets say you have a Json response from a web server you wish to parse, such as the example in the textbox below.

Now even though Javascript has built in functions for dealing with decoding and handling Json responses, we are using a Json response in this example for sake of example.

Let say we wish to extract all the text that can be found between "query":" and ","search_types".

When we have successfully accomplished this via Javascript double split function, the following will be returned:

Using the above example text in the above textbox, to use this function to extract the text we wish in Javascript:

Try this Javascript code for double split return multiple substrings for yourself.


S
H
A
R
E