How to split a string into an array, in JS

JavaScript: How to split a string into an array, in JS

You can use the split function on strings to return an array.

  1.             let tags = "photo,photos,dogsofinstagram";
  2.             let tagsArray = tags.split(","); // each word (tag) will be its own item in an array (it splits it wherever it found the comma.

webdevetc profile pic

I am a 29 year old backend web developer from London, mostly focusing on PHP and Laravel lately. This ( is my blog where I write about some web development topics (PHP, Laravel, Javascript, and some server stuff). contact me here.


Comments and discussion about How to split a string into an array, in JS

Found this interesting? Maybe you want to read some more in this series?

Or see other topics in the JavaScript language

Or see other languages/frameworks:
PHP Laravel Composer Apache CentOS and Linux Stuff WordPress General Webdev and Programming Stuff JavaScript
Or see random questions

How to force non www in htaccess

How to merge/concat two arrays together in JS?

What is the loop variable in a @foreach loop in Blade?

How to return JSON data to the user in Laravel?

How to show (or log) all SQL queries executed by Laravel

What is snake case?

What is the difference between reference and primitive data types types in Javascript?

How to set up an alias to map one directory to another destination

How to block an IP address in .htaccess

How do you run a PHP script from the command line?