- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Split a URL in JavaScript after every forward slash?
To split a URL, use the split() method. Use toString() before that. Let us see an example
Example
var newURL="http://www.example.com/index.html/homePage/aboutus/"; console.log(newURL); var splitURL=newURL.toString().split("/"); console.log(splitURL);
Above, we have set forward slash in the split() function, since we need to split the URL after every such slash.
To run the above program, you need to use the following command −
node fileName.js.
Output
Here, my file name is demo150.js. This will produce the following output −
PS C:\Users\Amit\JavaScript-code> node demo150.js http://www.example.com/index.html/homePage/aboutus/[ 'http:', '', 'www.example.com', 'index.html', 'homePage', 'aboutus', '' ]
- Related Articles
- How to replace before first forward slash - JavaScript?
- Possible to split a string with separator after every word in JavaScript
- Moving every alphabet forward by 10 places in JavaScript
- Squaring every digit of a number using split() in JavaScript
- Select text after last slash in MySQL?
- Why should we use a semicolon after every function in JavaScript?
- JavaScript Insert space after every two letters in string?
- Do I need to use a semicolon after every function in JavaScript?
- What prevents you from slipping every time you take a step forward?
- JavaScript example for Capturing mouse positions after every given interval
- JavaScript - Redirect a URL
- Replace() with Split() in JavaScript to append 0 if number after comma is a single digit
- MySQL query to split a column after specific characters?
- How can every violin in a violin plot be split in Python Seaborn Library?
- Writing a custom URL shortener function in JavaScript

Advertisements