.pop Получите второй элемент URL

var parts = 'http://mywebsite/folder/file'.split('/');
var lastSegment = parts.pop(1) || parts.pop();  // handle potential trailing slash

console.log(lastSegment);
 Run code snippetHide results
Tired Tarsier