Remove multiple elements from array in Javascript/jQuery

后端 未结 22 2175
梦毁少年i
梦毁少年i 2021-01-29 19:42

I have two arrays. The first array contains some values while the second array contains indices of the values which should be removed from the first array. For example:

<
22条回答
  •  爱一瞬间的悲伤
    2021-01-29 20:27

    Not in-place but can be done using grep and inArray functions of jQuery.

    var arr = $.grep(valuesArr, function(n, i) {
        return $.inArray(i, removeValFromIndex) ==-1;
    });
    
    alert(arr);//arr contains V2, V4
    

    check this fiddle.

提交回复
热议问题