我有两个数组,例如:

var a1 = ["1","3","4","5"]
var a2 = ["1","6","3","5"]


第二个数组用作存储。

我想比较这两个数组,例如,数字4在a1中,但不在a2中,因此我想将数字4推入a2
因此,每个不包含在a2中的数字都应推送到其中。

如何使用rxjs解决这种情况?

最佳答案

我能想到的最简单的方法是:

var a1 = ["1","3","4","5"];
var a2 = ["1","6","3","5"];

Observable.from(a1)
    .filter(val => a2.indexOf(val) === -1)
    .subscribe(val => {
        a2.push(val);
    });

console.log(a2);


打印到控制台:

[ '1', '6', '3', '5', '4' ]


观看现场演示:https://jsbin.com/gabesog/1/edit

关于javascript - RxJS过滤日期,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/41139113/

10-13 02:41