split a string into an array using split javascript

this will split the string into an array based on the spaces inbetween words. you can split it based on any character, for example if you had words in csv comma format you could use the second example.


// example using the spaces to split the string into an array
var the_string = "hi i am a string";
var string_to_array = the_string.split(" ");

// example showing the string split using a ,
var csv_like_string = "w1,s2,e3,r4,t6";
var csv_like_string_to_array = csv_like_string.split(",");


<div id='result' class='mb-3 alert alert-primary'>Check the console for the result...</div>
<button onclick='do_while_loop();' class='btn btn-primary hide'>Run do_while_loop()</button>


Check the console for the result...

Other Items in javascript
Page Views

This page has been viewed 223 times.

Search Code
Search Code by entering your search text above.

This is my test area for webdev. I keep a collection of code snippits here, mostly for my reference. Also if i find a good site, i usually add it here.