Lodash remove duplicates from array

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

This is my data:

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


        
7条回答
  •  野性不改
    2020-11-29 17:29

    With lodash version 4+, you would remove duplicate objects either by specific property or by the entire object like so:

    var users = [
      {id:1,name:'ted'},
      {id:1,name:'ted'},
      {id:1,name:'bob'},
      {id:3,name:'sara'}
    ];
    var uniqueUsersByID = _.uniqBy(users,'id'); //removed if had duplicate id
    var uniqueUsers = _.uniqWith(users, _.isEqual);//removed complete duplicates
    

    Source:https://www.codegrepper.com/?search_term=Lodash+remove+duplicates+from+array

提交回复
热议问题