JavaScript - Dictionary is empty -


i'm using appcelerator , want know if dictionary in js empty.

i've tried this:

var options = {};  // option 1 object.keys(options).length 1  //option 2 isempty(options) false  function isempty(ob){       for(var in ob){ if(ob.hasownproperty(i)){return false;}}       return true; }  //option 3 json.stringify(options) === '{}' false 

finally found problem: added 1 key value 'undefined' , json.stringify() function didn't show me key.

so, function object.keys(options).length works perfectly.

caution keys value 'undefined', check this function object.keys(options) because json.stringify return empty dictionary {}

var dict = {    cat: undefined }  ti.api.debug("dict: " + json.stringify(dict)) >  dict: {} ti.api.debug("keys: " + object.keys(options).length) > keys: 1 ti.api.debug("keys str: " + object.keys(options)) > keys: cat  var dict = {}  ti.api.debug("dict: " + json.stringify(dict)) >  dict: {} ti.api.debug("keys: " + object.keys(options).length) > keys: 0 ti.api.debug("keys str: " + object.keys(options)) > keys: 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -