Jquery 遍历数组

1、$.each()

$.each(object,function(index,e){  ...  });    
 
object --> 需要遍历的对象或数组
index  --> 索引    
e      --> 循环的每个元素

示例一:

let temp = "";
$.each(selected, function (index, obj) {
            if (index != selected.length - 1) {
                    temp = temp + obj.id+ ",";
            } else {
                    temp = temp + obj.id;
            }
 })

示例二:

let t = "";
selected.each(function (index, obj) {
          if (index, obj) {
                 t = t + obj.id + ",";
          } else {
                 t = t + obj.id;
          }
})

 

上一篇:jQuery元素操作


下一篇:P66:对象数组的for-each循环、如何设计能传递任意数量参数的函数?