SOURCE

let getFirstPath = (path) => {
    if (path.lastIndexOf('/') !== 0) {
        path = path.substring(0, path.lastIndexOf('/'))
        return getFirstPath(path)
    } else {
        return path
    }
}


let str = '/test'
console.log(getFirstPath(str))
console 命令行工具 X clear

                    
>
console