in this article, we will tell you how to convert a string to an array by a split method using javascript(Javascript string to array by split() method). sometimes we need to string into a javascript array. we use to commas, spaces and pipe signs for the string to array.
Now, in the below following example we will take a string and convert it into a javascript array. here, in the below following example, we use space delimited. so you can follow the below example.
1 2 3 4 | <script type="text/javascript"> var fruit = "Apple Mango Watermelon Orange Cherry Grape"; console.log(fruit.split(' ')); </script> |