javascript - Converting circular structure to JSON in my object -


var mapobjects = $('#placeholdslots div').map(function (i, n) {      var awardid = $(n).find('.dropped').attr('id');     var itemtype = $(n).find('.dropped').attr('data');       var obj = {};     obj['itemid'] = parseint(awardid) || "";     obj['type'] = itemtype || ""     return obj;  });  console.log(json.stringify(mapobjects)); 

any idea why can't json.stringify object? last line return error of

uncaught typeerror: converting circular structure json 

for me fine :

enter image description here

i didn't see circular reference problem object..

$.fn.map() returns jquery object ? note, if selecting div.dropped child element within #placeholdslots div parent element , $.map() iterate both div , div.dropped elements ; substituted selector $('#placeholdslots div:not(.dropped)') $('#placeholdslots div') @ stacksnippets

try utilizing $.map() , returns array,

var mapobjects = $.map($("#placeholdslots div:not(.dropped)")                   , function (n, i) {                        var awardid = $(n).find(".dropped").attr("id");                       var itemtype = $(n).find(".dropped").attr("data");                               var obj = {};                       obj["itemid"] = parseint(awardid) || "";                       obj["type"] = itemtype || ""                       return obj;              });            console.log(json.stringify(mapobjects));
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js">  </script>  <div id="placeholdslots">    <div><div id="123" class="dropped" data="abc">dropped</div></div>    <div><div id="456" class="dropped" data="def">dropped</div></div>  </div>


Comments

Popular posts from this blog

node.js - How to mock a third-party api calls in the backend -

visual studio - NuGet Automatic Package Restore when using git submodules -

node.js - Why do I get "SOCKS connection failed. Connection not allowed by ruleset" for some .onion sites? -