Home  >  Article  >  Web Front-end  >  JQuery each打印JS对象的方法_jquery

JQuery each打印JS对象的方法_jquery

WBOY
WBOYOriginal
2016-05-16 17:15:35797browse

我们知道javascript可以用alert输出变量的值,但是有时候返回的是一个对象,json格式的数据,jQuery可以用这个方法循环遍历读出对象的值,假如这个对象名称是obj,循环遍历打印它的值:

复制代码 代码如下:

  $.each(obj,function(key,val){
      if($.isPlainObject(val) || $.isArray(val)){
          subObj(val);
      }else{
          alert(key+'='+val);
      }
  });
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn