Summary of various jQuery example codes for traversing arrays and json objects

伊谢尔伦
Release: 2017-07-19 13:58:06
Original
1287 people have browsed it

jquery grep() filters and traverses the array


$().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
        
Copy after login

jquery each() filters and traverses the array


$().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); } ); } );
Copy after login

jquery inArray() filters and traverses the array


$().ready( function(){ var anArray = ['one','two','three']; var index = $.inArray(‘two',anArray); alert(index);//返回该值在数组中的键值,返回1 alert(anArray[index]);//value is two } );
Copy after login

jquery map() filters and traverses the array


$().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]); } } );
Copy after login

jquery traversal and parsing json object 1:


##

var json = [{dd:'SB',AA:'东东',re1:123},{cccc:'dd',lk:'1qw'}]; for(var i=0,l=json.length;i
        
Copy after login

jquery traverses and parses json objects 2


//有如下 json对象: var obj ={”name”:”冯娟”,”password”:”123456″,”department”:”技术部”,”sex”:” 女”,”old”:30}; //遍历方法: for(var p in obj){ str = str+obj[p]+','; return str; }
Copy after login

The above is the detailed content of Summary of various jQuery example codes for traversing arrays and json objects. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!