Link to home
Start Free TrialLog in
Avatar of mgmhicks

asked on

How to convert into json string from variable

I have the following statement

  var test = { 'PropertyID': 'CL' };

if gets used to pull data from the server.    

   data: JSON.stringify(test),

 works fine I always get the CL data.  However I need to create that same string but The CL will change, and gotten from a local storage.  This is what I have tried with no success so far.  Thanks in advance for fixing this for me.

 var myProperty = localStorage.getItem("SelectedProperty")

        var test2 = '{'+'PropertyID'+':'+ myProperty +'}'
Avatar of Chris Stanyon
Chris Stanyon
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mgmhicks


thanks your right, forgot about stringify
Nothing to do with stringify - there's just no need for all the quotes when creating an object.