forEach和each遍歷數組的使用方式,一般用於遍歷接收到的後臺數據

// foreach遍歷數組 var arr = [{name:"limeng",email:"xfjylimeng"},{name:"hehe",email:"xfjylimeng"}]; arr.forEach(myfun) function myfun(element,index,array){ // element: 指向當前元素的值 // index: 指向當前索引 // array: 指向Array對象本身 console.log(element.name); } // 遍歷一個數組通常用each 一般從後臺傳入過來的數據基本是用each遍歷 $.each([{name:"limeng",email:"xfjylimeng"},{name:"hehe",email:"xfjylimeng"}],function(i,n) { // alert("索引:"+i+"對應值爲:"+n.name); console.log(n.email); });
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章