Last active
August 29, 2015 14:13
-
-
Save joeSaad/fde88bb3140201a6ad40 to your computer and use it in GitHub Desktop.
Create JSON object from string, string could be a cookie.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var person = "name=Joe;age=34;location=Texas;hobby=soccer"; | |
var ca = person.split(';'); | |
var obj = {}; | |
for (var i= 0; i<ca.length; i++){ | |
var loc = ca[i].indexOf('='); | |
var p = ca[i].slice(0, loc); | |
eval("obj." + p + " = '" + ca[i].slice(loc+1) + "'"); | |
} | |
alert(JSON.stringify(obj)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment