How to convert into json string from variable

mgmhicks
mgmhicks used Ask the Experts™
on
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 +'}'
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2018
Distinguished Expert 2018
Commented:
Why all the quotes. This should do it:

var test2 = { PropertyID: myProperty }

Author

Commented:
thanks your right, forgot about stringify
Most Valuable Expert 2018
Distinguished Expert 2018

Commented:
Nothing to do with stringify - there's just no need for all the quotes when creating an object.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial