Q:

Write a JavaScript program to break an address of an url and put it's part into an array

0

Write a JavaScript program to break an address of an url and put it's part into an array.  
Note: url structure : ://.org[/] and there may be no part in the address.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

function break_address(url_add) {
    var data = url_add.split("://")
    var protocol = data[0];
    data = data[1].split(".com");
    var domain = data[0];
    data = data[1].split("/");

    if(data[1]){
        return [protocol,domain,data[1]]
    }

    return [protocol,domain]
}

var url_add = "https://www.w3resource.com/javascript-exercises/"
console.log("Original address: "+url_add)
console.log(break_address(url_add))

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now