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;
          }
})
原文地址:https://www.cnblogs.com/wongzzh/p/15097403.html