Lodash remove duplicates from array

后端 未结 7 686
慢半拍i
慢半拍i 2020-11-29 17:12

This is my data:

[
    {
        url: \'www.example.com/hello\',
        id: \"22\"    
    },
    {
        u         


        
7条回答
  •  独厮守ぢ
    2020-11-29 17:37

    Simply use _.uniqBy(). It creates duplicate-free version of an array.

    This is a new way and available from 4.0.0 version.

    _.uniqBy(data, 'id');
    

    or

    _.uniqBy(data, obj => obj.id);
    

提交回复
热议问题