Filter a 2D Array From Elements of Another

后端 未结 1 1885
情歌与酒
情歌与酒 2021-01-23 11:03

I have two sets of numeric elements stored as 2D array. The values were grabbed from a column using .getValues(). One is a full list the other is a partial list. I

1条回答
  •  执笔经年
    2021-01-23 11:37

    It seems you have something like this:

    var full = [[1],[2],[3],[4],[5]]
    var partial = [[3],[4]]
    
    var result = full.filter(x => !partial.find(p => p[0] === x[0]))
    console.log(result)

    This will filter the way you want. Simply put your filter does not work since you did not take into account the result returned, which is [[], [], []] or array of arrays.

    So in your context try this:

    var arr = fullListArr.filter(item => !partialListArr.find(p ==> p[0] === item[0]);
    

    0 讨论(0)
提交回复
热议问题