$().ready( function(){ var anArray = ['one','two','three']; var index = $.inArray(‘two',anArray); alert(index);//返回该值在数组中的键值,返回1 alert(anArray[index]);//value is two } );
jquery map()筛选遍历数组
代码如下:
$().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]); } } );
js遍历解析json对象1
代码如下:
var json = [{dd:'SB',AA:'东东',re1:123},{cccc:'dd',lk:'1qw'}]; for(var i=0,l=json.length;ifor(var key in json[i]){ alert(key+':'+json[i][key]); } }
js遍历解析json对象2
有如下 json对象: var obj ={”name”:”冯娟”,”password”:”123456″,”department”:”技术部”,”sex”:” 女”,”old”:30}; 遍历方法:
代码如下:
for(var p in obj){ str = str+obj[p]+','; return str; }