S
S
sanan :o2014-08-19 15:24:40
JavaScript
sanan :o, 2014-08-19 15:24:40

How to parse location.hash in such a way as to put it into an array (as a key=value pair) and output something like this: alert(data.value1)?

Hello dear) So, I have this:

urlHash=location.hash.slice(1); 
alert(urlHash); // выводит param1=value1&param2=value2

I need to parse it so that it outputs something like this:
alert(urlHash.param1); // нужно чтобы выводило value1, так же и с другими параметрами

Thank you very much in advance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeny Petrov, 2014-08-19
@sanantech

There is even no need for regular seasons with their powerful exec

var params = location.hash.slice(1).split('&'),
  result = {};

for (var i = 0; i < params.length; i++) {
  var _result = params[i].split('=');

  result[_result[0]] = _result[1];
}

Why are you passing typical GET parameters to hash?
Update: updated for JSLint fans :)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question