I'm new to javascript and had a quick question.
Here's what I'm trying to accomplish.
myArray = ["Jack Ripper", "John Parker"];
I'd like to return an array by breaking up the input string into individual words. For example "Jack Ripper" would be returned as ["Jack", "Ripper"]
I don't know what this is called but would sure like to learn. Any help or a point in the right direction would be much appreciated.
In general this is called string splitting. Pretty much every language will have built in tools to do this. In my example I have used a space (" ") as my delimiter, but you can split a string by pretty much anything. For example, if you had "Jack,Ripper" you could use split(",").
var str = "Jack Ripper";
var result = str.split(" ");
produces
result[0] = Jack
result[1] = Ripper
You should be able to use this example to do whatever you need concerning larger strings, different delimiters, etc...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With