关于数组 字符串和两个数组合并的一些记录

两个数组合并成一个。
var allrenyuan =[];
senator = ‘小明’,'小红','小绿','小黄','小黑';
senatorIds = [‘1’,'2','3','4','5'];
$.each(senator.split(','),function (i,item) {
    var obj = {};
    obj.senator = item;
    obj.senatorIds = senatorIds[i];

    allrenyuan.push(obj);
});
console.log("allrenyuan = "+allrenyuan);

数组过滤   A 包含B    A-B=C
//计算缺席人员姓名
var qxrenyuan =[];
sdrenyuan = [‘1’,'2','3','4','5'];
qbrenyuan = [‘1’,'2','3','4','5','6','7'];
$.each(sdrenyuan, function (i, item) {
    $.each(qbrenyuan, function (j, tmp) {
        if (sdrenyuan[i] === qbrenyuan[j]) {
            qbrenyuan.splice(j, 1);
        }
    });
});
qxrenyuan = qbrenyuan;

数组变成字符串

sdrenyuan = [‘1’,'2','3','4','5'];

aa = sdrenyuan.toString();

console.log(aa); // aa=> 1,2,3,4,5

猜你喜欢

转载自blog.csdn.net/Cai_javaXiaoFan/article/details/89173858
今日推荐