<html>
<head>
  <meta charset="utf-8">
  <title>Mocha Tests</title>
  <link href="https://unpkg.com/mocha@5.2.0/mocha.css" rel="stylesheet" />
</head>
<body>
  <div id="mocha"></div>

  <script src="https://unpkg.com/chai/chai.js"></script>
  <script src="https://unpkg.com/mocha@5.2.0/mocha.js"></script>

  <div></div>
  

</body>
</html>
const arr = [
  { id: 1, name: "king" },
  { id: 2, name: "master" },
  { id: 3, name: "lisa" },
  { id: 4, name: "ion" },
  { id: 5, name: "jim" },
  { id: 6, name: "gowtham" },
  { id: 1, name: "jam" },
  { id: 1, name: "lol" },
  { id: 2, name: "kwick" },
  { id: 3, name: "april" },
  { id: 7, name: "sss" },
  { id: 8, name: "brace" },
  { id: 8, name: "peiter" },
  { id: 5, name: "hey" },
  { id: 6, name: "mkl" },
  { id: 9, name: "melast" },
  { id: 9, name: "imlast" },
  { id: 10, name: "glow" }
];





function getUnique(arr,comp){

                    //store the comparison  values in array
   const unique =  arr.map(e=> e[comp]). 
                  // store the keys of the unique objects
                  map((e,i,final) =>final.indexOf(e) === i && i) 
                  // eliminate the dead keys & return unique objects
                 .filter((e)=> arr[e]).map(e=>arr[e]);
  
  return unique
       
}

 





mocha.setup('bdd');


var assert = chai.assert;

describe('Remove duplicate objects from array',()=>{
  
  it("unique objects ",()=>{
     const u =  getUnique(arr,'id')
   
     assert.deepEqual(
[
  {
    id: 1,
    name: "king"
  },
  {
    id: 2,
    name: "master"
  },
  {
    id: 3,
    name: "lisa"
  },
  {
    id: 4,
    name: "ion"
  },
  {
    id: 5,
    name: "jim"
  },
  {
    id: 6,
    name: "gowtham"
  },
  {
    id: 7,
    name: "sss"
  },
  {
    id: 8,
    name: "brace"
  },
  {
    id: 9,
    name: "melast"
  },
  {
    id: 10,
    name: "glow"
  }
],u)
  
  })

 
  
})



mocha.run()

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

  1. https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.11/lodash.min.js