Find domain name from an URL using angular JS


How we found a domain name i.e from and URL (

What is URL?

A URL is one type of Uniform Resource Identifier (URI); the generic term for all types of names and addresses that refer to objects on the World Wide Web. The term “Web address” is a synonym for a URL that uses the HTTP or HTTPS protocol.

What is domain name?

The part of a network address which identifies it as belonging to a particular domain.

How to find a domain name from an url using angular js

<!DOCTYPE html>
<script src=""></script>

<ul ng-app="myApp" ng-controller="myCtrl">
<li ng-repeat="x in names">
    {{x | u2d}}

var app = angular.module('myApp', []);
// url to domain
app.filter('u2d', function() {
    return function(url) {
    var domain;
    if (url.indexOf("://") > -1) {
        domain = url.split('/')[2];
    else {
        domain = url.split('/')[0];
    domain = domain.split(':')[0];
    return domain;
app.controller('myCtrl', function($scope) {
    $scope.names = [

<p>Make your own filters.</p>
<p>This filter, called "u2d", will convert the URL into domain.</p>

The result is :

find domain name from url