javascript - Convert string of variables separated by & into array -


this question has answer here:

i want grab variables contained in url after logs facebook app.

for example:

// window.location = .../#access_token=cttg4ft3ci...&expires_in=5298 hash = window.location.hash; data = parse(hash); console.log(data['access_token'] + ', ' + data['expires_in']); // returns: caag4ft3ci..., 5298 

is there method or function similar json.parse() convert "hash" array or object?

function parse (hash) {     var l, chunk, = 0, out = {};     var chunks = hash.substr(1).split('&');     ( l = chunks.length; < l; i++ ) {         chunk = chunks[i].split('=');         out[ chunk[0] ] = chunk[1];     }     return out; } 

here's fiddle: http://jsfiddle.net/vwljs/


Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -