js和jQuery遍历json对象和数组
来源:互联网 发布:mysql front 乱码 编辑:程序博客网 时间:2024/06/17 07:38
javascript和jQuery遍历数组,json对象和json数组的多种方法。
/** jquery each()筛选遍历数组 */function eachArray(){ var anArray = ['zero','one','two']; $.each(anArray,function(index) { console.log(index); }); $.each(anArray,function(index,value){ console.warn(index); console.warn(value); }); }/** jquery each()筛选遍历JSON数对象*/function eachJson(){var anObject = {one:1,two:2,three:3};$.each(anObject,function(key) { console.log(key); }); $.each(anObject,function(key,value) { console.info(key); console.info(value); });}/** jquery each()筛选遍历JSON数数组*/function eachJsonArr(){var arr = [{one:1,two:2,three:3},{"A":1,B:2,C:3}];$.each(arr,function(index,value){ //这里的value就是上面的两个json对象,{}和{}console.info(value); $.each(value,function(key,value){console.info(key+":"+value);}); });}/* *js遍历json数组*/function jsonArr(){var arr = [{dd:'ww',AA:'东东',re1:123},{cccc:'dd',lk:'1qw'}]; for(var i=0,l=arr.length;i<l;i++){ for(key in arr[i]){ console.info(key+':'+arr[i][key]); } } }/* *js遍历json对象*/function jsonObj(){var json ={'name':'冯娟','password':'123456','department':'技术部','sex':' 女','old':30};for(key in json){ console.info(key+':'+json[key]); } }
还有一些不常用的方法
/* jquery grep()筛选遍历数组 , * 将数组通过筛选,获得一个新的数组,遍历*/function grepArray(){var array = [1,2,3,4,5,6,7,8,9]; var filterarray = $.grep(array,function(value){ return value > 5;//筛选出大于5的 }); for(var i=0;i<filterarray.length;i++){ console.info(filterarray[i]); } for (key in filterarray){ console.warn(filterarray[key]);} }/** jquery inArray()筛选遍历数组 */function inArray(){var anArray = ['one','two','three']; var index = $.inArray('two',anArray); console.info(index);//返回该值在数组中的索引值,返回1 console.info(anArray[index]);//value is two }
0 0
- js和jQuery遍历json对象和数组
- js、jquery遍历数组和对象
- 用jquery实现cookie的操作以及创建js数组和遍历js数组,js对象,jquery.json的使用
- JS 遍历 json 和 JQuery 遍历json
- Jquery 遍历json和数组
- Js 遍历对象和遍历数组
- js遍历对象和遍历数组
- jquery遍历筛选数组的几种方法和遍历解析json对象
- jquery遍历筛选数组的几种方法和遍历解析json对象
- jquery遍历筛选数组的几种方法和遍历解析json对象
- jquery遍历筛选数组的几种方法和遍历解析json对象
- Jquery遍历筛选数组的几种方法和遍历解析json对象|Map()方法详解
- jquery遍历筛选数组的几种方法和遍历解析json对象
- jquery遍历筛选数组的几种方法和遍历解析json对象
- jquery遍历筛选数组的几种方法和遍历解析json对象
- js遍历数组、对象、json
- js/jquery遍历对象/数组
- js对象和数组的遍历
- lua读取xml
- 分析类
- Android开发笔记(十七)GIF动画的实现GifAnimation
- 统计某个端口的访问量
- Qt浅谈之三十七界面文字显示动态化
- js和jQuery遍历json对象和数组
- [算法]KMP算法
- Html5(1)
- hax kernel module is not install
- Xcode清除编译缓存
- AlertDialog使用
- 不花钱开店 网上发布产品 最便宜的推广(第一章)
- 关于不是tableView怎么刷新数据
- Hello Mybatis 03 数据关联