What is the point jQuery.parseJSON (JSON.stringify (someData));

In this fragment

var someDataJSON = jQuery.parseJSON(JSON.stringify(someData));

According to MDN, the internal method converts the JavaScript value to a JSON string; then the external method "takes a properly formed JSON string and returns the resulting JavaScript value" in jQuery

If you start with a JS value and get a JS value, is this a meaningless operation?

+4
source share
2 answers

This is usually a trick used to get a copy of an object by value in javascript. (Since all objects are passed by reference). You can find a more detailed answer on how to do this, if you're interested, in this postoverflow post

+4

someDataJSON - JSON, . javascript " " [ " " ], .

var copyJSONObj = JSON.parse(JSON.stringify(JSONObj))

, .

+2

All Articles