JQuery each method for printing JS objects

  • 2020-03-29 23:45:11
  • OfStack

We know that javascript can use alert to output the value of a variable, but sometimes it returns an object, data in json format. JQuery can use this method to loop over and read the value of the object. If the object name is obj, loop over and print its value:

  $.each(obj,function(key,val){
      if($.isPlainObject(val) || $.isArray(val)){
          subObj(val);
      }else{
          alert(key+'='+val);
      }
  });

Related articles: