jquery筛选数组之grep、each、inArray、map的用法及遍历json对象
来源:互联网 发布:python中异常处理 编辑:程序博客网 时间:2024/05/22 03:26
jquery筛选数组之grep、each、inArray、map的用法及遍历json对象
grep
<script type='text/javascript' src="/jquery.js"></script>
<script type="text/javascript">
$().ready(
function(){
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++){
alert(filterarray[i]);
}
for (key in filterarray){
alert(filterarray[key]);
}
}
);
</script>
each
<script type='text/javascript' src="/jquery.js"></script>
<script type="text/javascript">
$().ready(
function(){
var anObject = {one:1,two:2,three:3};//对json数组each
$.each(anObject,function(name,value) {
alert(name);
alert(value);
});
var anArray = ['one','two','three'];
$.each(anArray,function(n,value){
alert(n);
alert(value);
}
);
}
);
</script>
inArray
<script type='text/javascript' src="/jquery.js"></script>
<script type="text/javascript">
$().ready(
function(){
var anArray = ['one','two','three'];
var index = $.inArray('two',anArray);
alert(index);//返回该值在数组中的键值,返回1
alert(anArray[index]);//value is two
}
);
</script>
map
<script type='text/javascript' src="/jquery.js"></script>
<script type="text/javascript">
$().ready(
function(){
var strings = ['0','1','2','3','4','S','6'];
var values = $.map(strings,function(value){
var result = new Number(value);
return isNaN(result) ? null:result;//isNaN:is Not a Number的缩写
}
);
for (key in values) {
alert(values[key]);
}
}
);
</script>
遍历json对象:
<script>
var json = [{dd:'SB',AA:'东东',re1:123},{cccc:'dd',lk:'1qw'}];
for(var i=0,l=json.length;i<l;i++){
for(var key in json[i]){
alert(key+':'+json[i][key]);
}
}
</script>
遍历json对象
有如下 json对象:
var obj ={”name”:”冯娟”,”password”:”123456″,”department”:”技术部”,”sex”:” 女”,”old”:30};
遍历方法:
for(var p in obj){
str = str+obj[p]+’,';
return str;
}
- $.grep ,$.map,jquery筛选数组之grep、each、inArray、map的用法及遍历json对象
- jquery筛选数组之grep、each、inArray、map的用法及遍历json对象
- jquery筛选数组之grep、each、inArray、map的用法及遍历json对象
- jquery筛选数组之grep、each、inArray、map的用法及遍历json对象
- jquery筛选数组之grep、each、inArray、map的用法及遍历json对象 [转]
- jquery筛选数组之grep、each、inArray、map的用法及遍历json对象
- jquery筛选数组之grep、each、inArray、map的用法及遍历json对象
- jquery筛选数组之grep、each、inArray、map的用法及遍历json对象
- Jquery遍历筛选数组的几种方法和遍历解析json对象|Map()方法详解
- jQuery数组处理完全详解($.each,$.grep,$.map,$.merge,$.inArray,$.unique,$.makeArray)
- jQuery数组($.each,$.grep,$.map,$.merge,$.inArray,$.unique,$.makeArray)处理函数详解
- jQuery数组($.each,$.grep,$.map,$.merge,$.inArray,$.unique,$.makeArray)处理函数详解
- jQuery数组($.each,$.grep,$.map,$.merge,$.inArray,$.unique,$.makeArray)处理函数详解
- 用jquery的each方法介绍及遍历json对象
- jquery $.each()遍历json数组
- JQuery 操作数组 each、map、grep
- JQuery 操作数组 each、map、grep、filter
- JQuery 操作数组 each、map、grep
- [linux网络] iptables+ip route 实现双线上网流量分割
- XML string 转datagrid datatable dataset
- 在windows xp下如何彻低卸载oracle客户端(8i,其他类似)
- 两个Ubuntu创建桌面启动程序的方法
- C#创建用户控件:IPv4地址输入框
- jquery筛选数组之grep、each、inArray、map的用法及遍历json对象
- 如何修改SAP 登录后的背景图片(事务码 SMW0,SM30)
- Emacs 窗体的透明设置
- CString.Format 用法
- linux下php调用系统命令(root权限)
- Unity3D之iOS拍照
- json 基本原理
- GetBuffer, ReleaseBuffer, GetBufferSetLength
- directshow自带sample概要介绍