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
webdevetc

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



More...


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 increment a value in the database

How to set the Expires header in .htaccess

How to prevent Eloquent from adding created_at or updated_at timestamps?

How to block multiple IP addresses in .htaccess

What is Bubble sort, and how to write an implementation of it in PHP

What does PEAR stand for?

Set PHP config Variables (like ini_set) with .htaccess

How to set environmental variables in your .htaccess file

How to namespace a Laravel route group?

How to review blog posts (written by other users) before they get published on your WordPress blog?