Split String to An Array
For splitting string to array we'll use split() method which takes a argument consisting of special character. Let's see the below code snippet.
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>split string to array - shouts.dev</title> </head> <body> <script> var string = "A+B+C+C+D+E+F+G+H"; console.log(string.split('+')); </script> </body> </html>
Which will produce the below output.
split() is quite handy method for creating arrays from an array. For more info about split() see here.
That's it for today. Hope you've enjoyed this tutorial. Catch me in the comment section if anything goes wrong. Thanks for reading.