+ 3

Get just name from url with JavaScript

i want to JavaScript function that take url as parameter and return just name from url, for example; parameter url: https//:www.facebook.com/something or https//Facebook.com/something or www.facebook.com/something or facebook.com/something and i want get return just facebook or facebook.com

17th Mar 2018, 8:47 AM
Muhammad Irfan ✓
Muhammad Irfan ✓ - avatar
2 Réponses
+ 6
two methods: one using new URL(url) and one using regex which is more flexible (can probably make a better regex than this one) https://code.sololearn.com/WwAkr4Nds2GN/?ref=app
17th Mar 2018, 9:49 AM
Burey
Burey - avatar
+ 1
good job bro
17th Mar 2018, 1:00 PM
Muhammad Irfan ✓
Muhammad Irfan ✓ - avatar