Are you first timer at lazacode.org? Why not join us and start exchange your programming knowledge with everyone. Register today!

JS - Get specific slash value on URL with split()

0 votes
3 views
added Feb 12 in Javascript by lcjr Sergeant (2,120 points)
var newsUrl = window.location.href,
    newsSplit = newsUrl.split('/'),
    newsId = newsSplit[newsSplit.length-2]; 
console.log(newsId);

// e.g URL:
// http://yoursite.com/content/1643743/defender-110-td5-2006-England

// output newsId
// 1643743

 

Please log in or register to response this reference.

lazacode.org - Malaysia's programming knowledge sharing platform, where everyone can share their finding as reference to others.
...