Remove entry from array using another array

前端 未结 7 2143
迷失自我
迷失自我 2021-01-25 09:12

Not sure how do to this, so any help is greatly appreciated

Say I have :

const array1 = [1, 1, 2, 3, 4];
const array2 = [1, 2];

Desired

7条回答
  •  离开以前
    2021-01-25 09:23

    Not sure the most efficiency way to do this in modern JS, and I'm pretty old-school, so here's an old-school solution:

     var array1 = [1, 1, 2, 3, 4];
        var array2 = [1, 2];
        
        // Note this method is destructive
        Array.prototype.removeFirstValueMatch = function(ar)
        {
        	var indexesToRemoveAr = [];
        	var indexesToRemoveOb = {};
        	for(var i=0, j; i

提交回复
热议问题