Shift js string single character

In PHP, it's pretty simple, I would suggest array_shift($string)?

If not, I'm sure there is an equally simple solution :)

However, is there a way to achieve the same in JavaScript?

My specific example is extracting window.location.hashfrom the address bar to dynamically load a specific AJAX page. If the hash is 2, that is, http: //foo.bar.com#2 ...

var hash = window.location.hash; // hash would be "#2"

Ideally, I would like to remove #so that the function is simple 2.

Thank!

+4
source share
3 answers
hash = hash.substr(1);

hash . PHP substr, , , , , PHP, array_shift ( , array_shift !)

+11

, shift() Array.

Array s, " " , shift() String, split():

var char = str.split("").shift();
+2

, , , , , :

var hash = window.location.split("").pop();
0

Source: https://habr.com/ru/post/1753637/


All Articles