Compare the two arrays to remove the extra part and subtract the duplicate part

Compare the two arrays to take out the extra part:

let jianshao = '' //减少的
for(let item of oldVal) { 
    let stra = item;
    let count = 0;
    for(let j = 0; j < val.length; j++) {
        let strb = val[j];
        if(stra == strb) {
            count++;
        }
    }
    if(count === 0) { 
       jianshao = stra;
    }

Compare the two arrays and subtract the duplicates:

let newarr = []
var tmp = oldVal.concat(allYuanquValues);
var o = {};
for (let i = 0; i < tmp.length; i ++){
    (tmp[i] in o) ? o[tmp[i]] ++ : o[tmp[i]] = 1;
}
for (let x in o) {
    if (o[x] == 1){
        newarr.push(x);
    }
}

 

Guess you like

Origin blog.csdn.net/AN0692/article/details/107312100