How to get path from full path in JavaScript

Strings
Last updated Apr 28, 2018
const url = "/Users/code/codetogo/index.html";

url.substr(0, url.lastIndexOf("/") + 1);
/Users/code/codetogo/