0

I have a hash in the URL that I've dynamically created using checkboxes, on the page load/document ready I'm checking to see if a hash exists and then if it does I want to loop through each string and do something with them.

for example my hash looks like these below.

#thing1/thing2/thing3/thing4/thing5/thing6/thing7/thing8/

#thing1/thing2/thing3/

#thing1/thing3/thing5/thing7/thing9/

The first thing I do is remove the actual hash

window.location.hash.substring(1);

Now I have something like:

thing1/thing2/thing3/

I want to get thing1, thing2 and thing3 and store them in a format I can loop over, maybe like this:

var urlStrings = ["thing1", "thing2", "thing3"];

I hope someone is able to help me solve this problem, any help/advice is much appreciated.

1

2 Answers 2

2

Use .split function, like this

var urlStrings = window.location.hash.substring(1).split("/");
Sign up to request clarification or add additional context in comments.

Comments

0

Split them like this:

var str = 'thing1/thing2/thing3';
str.split('/');

And you can use indexes to get them:

str[1];//thing2

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.