dedup-array

1.0.1 • Public • Published

Intro

Filter duplicate object in Array by certain key name. 对象数组去重:过滤对象数组中指定键名的重复值,不会比较其他键值,不会合并。

install

npm i dedup-array

Usage

let filteredArr = dedup(array,["key1","key2"])

Demo

let dedup = require("dedup-array");
let array = [
    {
        id: 1,
        name: '1',
        prop: {
            url: "url1",
            description: "des1"
        }
    },
    {
        id: 1,
        name: '2',
        prop: {
            url: "url2",
            description: "des2"
        }
    },
    {
        id: 3,
        name: '3',
        prop: {
            url: "url3",
            description: "des1"
        }
    },
]
console.log("input", array)
console.log('key=["id"]:\n', dedup(array, ['id']))
console.log('key=["prop","description"]:\n', dedup(array, ['prop', 'description']))

result

input [
  { id: 1, name: '1', prop: { url: 'url1', description: 'des1' } },
  { id: 1, name: '2', prop: { url: 'url2', description: 'des2' } },
  { id: 3, name: '3', prop: { url: 'url3', description: 'des1' } }
]
key=["id"] 
[
  { id: 1, name: '1', prop: { url: 'url1', description: 'des1' } },
  { id: 3, name: '3', prop: { url: 'url3', description: 'des1' } }
]
key=["prop","description"]
[
  { id: 1, name: '1', prop: { url: 'url1', description: 'des1' } },
  { id: 1, name: '2', prop: { url: 'url2', description: 'des2' } }
]

Readme

Keywords

none

Package Sidebar

Install

npm i dedup-array

Weekly Downloads

0

Version

1.0.1

License

ISC

Unpacked Size

3.72 kB

Total Files

5

Last publish

Collaborators

  • rackar