The split method splits a string into an array of strings by separating it into substrings. This tool is extremely useful. As an example, we’ll take apart the query string parameters of a URL.

var url = "http://www.example.com/category/page?query=true&query2=false"; // Split off the query string parameters var query = url.split("?")[1]; // "query=true&query2=false" // Now split up the params var params = query.split("&"); // ["query=true", "query2=false"] // Loop through the params and split the key and the value for (var i=0; i < params.length; i++) { console.log(params[i].split("=")[0], params[i].split("=")[1]); } // query true // query2 false

The split method splits a string into an array of strings by separating it into substrings. This tool is extremely useful. As an example, we’ll take apart the query string parameters of a URL.

var url = "http://www.example.com/category/page?query=true&query2=false"; // Split off the query string parameters var query = url.split("?")[1]; // "query=true&query2=false" // Now split up the params var params = query.split("&"); // ["query=true", "query2=false"] // Loop through the params and split the key and the value for (var i=0; i < params.length; i++) { console.log(params[i].split("=")[0], params[i].split("=")[1]); } // query true // query2 false

The split method splits a string into an array of strings by separating it into substrings. This tool is extremely useful. As an example, we’ll take apart the query string parameters of a URL.

var url = "http://www.example.com/category/page?query=true&query2=false"; // Split off the query string parameters var query = url.split("?")[1]; // "query=true&query2=false" // Now split up the params var params = query.split("&"); // ["query=true", "query2=false"] // Loop through the params and split the key and the value for (var i=0; i < params.length; i++) { console.log(params[i].split("=")[0], params[i].split("=")[1]); } // query true // query2 false

How to Split a String into an Array in JavaScript

Jeremy Jeremy (10)
Total time: 5 minutes 
Updated: July 22nd, 2020

Learn how to split a string into an array.

Posted in these interests:

javascript
PRIMARY
27 guides
code
68 guides

How to Split a String into an Array in JavaScript

javascriptcode
Jeremy Jeremy (10)
Total time: 5 minutes 
Updated: July 22nd, 2020
Jeremy
1
 

Posted in these interests:

javascript
PRIMARY
27 guides
code
68 guides
javascript
PRIMARY
27 guides
code
68 guides
PRIMARY
Calling all writers!

We’re hiring. Write for Howchoo

1
 
In these interests
javascript
PRIMARY
27 guides
code
68 guides
javascript
PRIMARY
27 guides
code
68 guides
PRIMARY

The split method splits a string into an array of strings by separating it into substrings. This tool is extremely useful. As an example, we’ll take apart the query string parameters of a URL.

var url = "http://www.example.com/category/page?query=true&query2=false"; // Split off the query string parameters var query = url.split("?")[1]; // "query=true&query2=false" // Now split up the params var params = query.split("&"); // ["query=true", "query2=false"] // Loop through the params and split the key and the value for (var i=0; i < params.length; i++) { console.log(params[i].split("=")[0], params[i].split("=")[1]); } // query true // query2 false

The split method splits a string into an array of strings by separating it into substrings. This tool is extremely useful. As an example, we’ll take apart the query string parameters of a URL.

var url = "http://www.example.com/category/page?query=true&query2=false"; // Split off the query string parameters var query = url.split("?")[1]; // "query=true&query2=false" // Now split up the params var params = query.split("&"); // ["query=true", "query2=false"] // Loop through the params and split the key and the value for (var i=0; i < params.length; i++) { console.log(params[i].split("=")[0], params[i].split("=")[1]); } // query true // query2 false

The split method splits a string into an array of strings by separating it into substrings. This tool is extremely useful. As an example, we’ll take apart the query string parameters of a URL.

var url = "http://www.example.com/category/page?query=true&query2=false"; // Split off the query string parameters var query = url.split("?")[1]; // "query=true&query2=false" // Now split up the params var params = query.split("&"); // ["query=true", "query2=false"] // Loop through the params and split the key and the value for (var i=0; i < params.length; i++) { console.log(params[i].split("=")[0], params[i].split("=")[1]); } // query true // query2 false

String.split

Calling all writers!

We’re hiring. Write for Howchoo

Jeremy's profile pictureJeremy
Joined in 2015
Programmer, brogrammer, whoagrammer.
Jeremy's profile picture
Share this guide!
RedditEmailText
Related to this guide:
How to Pretty Print JSON in Chrome Developer ConsoleHow to Pretty Print JSON in Chrome Developer Console
In these interests: codejavascriptwebdev
Remove Elements From an Array in JavaScriptRemove Elements From an Array in JavaScript
When working with arrays in JavaScript, we often need to remove elements.
Tyler's profile picture TylerView
In these interests: codejavascript
Enumerable Properties in JavaScriptEnumerable Properties in JavaScript
Enumerable properties are properties whose internal enumerable flag set to true.
Tyler's profile picture TylerView
In these interests: codejavascript
How to Pretty Print JSON in Chrome Developer ConsoleHow to Pretty Print JSON in Chrome Developer Console
In these interests: codejavascriptwebdev
Zach's profile pictureViewcodejavascriptwebdev
Remove Elements From an Array in JavaScriptRemove Elements From an Array in JavaScript
When working with arrays in JavaScript, we often need to remove elements.
Tyler's profile picture TylerView
In these interests: codejavascript
Tyler's profile pictureViewcodejavascript
Enumerable Properties in JavaScriptEnumerable Properties in JavaScript
Enumerable properties are properties whose internal enumerable flag set to true.
Tyler's profile picture TylerView
In these interests: codejavascript
Tyler's profile pictureViewcodejavascript
People also read:
This guide demonstrates multiple ways to iterate over a JavaScript object’s properties and values.
There are two very similar statements in JavaScript: for…in and for…of. And while they can be easily confused, they’re actually quite different.
My journey trying to find the one loop operator to rule them all
As a JavaScript developer, you’ll often need to construct URLs and query string parameters. One sensible way to construct query string parameters is to use a one layer object with key value pairs.
Writing tests is an important part of software development process. Unit tests form a core part of testing process where each functional block is tested as an independent unit.
Making a deep copy of an object in JavaScript is fairly challenging. Fortunately, there are a few ways to accomplish this without much code.
At some point you’ll want to read, set, and remove cookies using JavaScript.
This guide will teach you how to concatenate, or join, all elements of an array into a single string.
Learn how to merge two arrays together in JavaScript.
Tabbed browsing has become the standard so modern browsers have provided a way for developers to determine if a tab has focus. This uses the HTML 5 Page Visibility API.
This guide demonstrates multiple ways to iterate over a JavaScript object’s properties and values.
There are two very similar statements in JavaScript: for…in and for…of. And while they can be easily confused, they’re actually quite different.
My journey trying to find the one loop operator to rule them all
As a JavaScript developer, you’ll often need to construct URLs and query string parameters. One sensible way to construct query string parameters is to use a one layer object with key value pairs.
Writing tests is an important part of software development process. Unit tests form a core part of testing process where each functional block is tested as an independent unit.
Learn Multiple Ways to Iterate Over JavaScript Object Properties and Values
The Difference Between “for…in” and “for…of” in JavaScript
JavaScript for loops
How to Turn an Object into Query String Parameters in JavaScript
Unit Testing in JavaScript – Mocha, Chai and Sinon – a Beginner’s Guide
Making a deep copy of an object in JavaScript is fairly challenging. Fortunately, there are a few ways to accomplish this without much code.
At some point you’ll want to read, set, and remove cookies using JavaScript.
This guide will teach you how to concatenate, or join, all elements of an array into a single string.
Learn how to merge two arrays together in JavaScript.
Tabbed browsing has become the standard so modern browsers have provided a way for developers to determine if a tab has focus. This uses the HTML 5 Page Visibility API.
How to Copy an Object in JavaScript
How to Manage Cookies in JavaScript
How to Join All Elements of an Array in JavaScript
How to Merge Two Arrays in JavaScript
Determine if a Tab has Focus in JavaScript
Posted in these interests:
javascriptjavascript
javascript
PRIMARY
Array(16).join(“wat” – 1) + ” Batman!”;
codecode
Code is poetry — one line at a time.
javascriptjavascript
javascript
PRIMARY
Array(16).join(“wat” – 1) + ” Batman!”;
PRIMARY
Explore
codecode
Code is poetry — one line at a time.
Explore
Discuss this guide:
We’re hiring!
Are you a passionate writer? We want to hear from you!
We’re hiring!
Are you a passionate writer? We want to hear from you!
View openings

Want to support Howchoo? When you buy a tool or material through one of our Amazon links, we earn a small commission as an Amazon Associate.

Donate

Leave a Reply

Your email address will not be published. Required fields are marked *