My problem:
I have a path like this fore example: some/path/with/unknown/depth
In this example i want to access depth
.
I know i can do it like this:
let path = "some/path/with/unknown/depth";
let word = path.split("/")[4];
But 4
is hardcoded. Is there any way to get the last element dynamically? One solution could be this here:
let path = "some/path/with/unknown/depth";
let words = path.split("/");
let word = words[words.length - 1];
Is it possible to get the last element just with 1 line?