push only unique elements in an array

后端 未结 6 1380
-上瘾入骨i
-上瘾入骨i 2021-01-19 14:25

I have array object(x) that stores json (key,value) objects. I need to make sure that x only takes json object with unique key. Below, example \'id\' is the key, so i don\'t

6条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-19 14:49

    Create a very readable solution with lodash.

    x = _.unionBy(x, [new Item(clickId, obj)], 'id');

提交回复
热议问题