unique object in array

    0

    0

    [{name: "Joe", date: "2018-07-01", amt: 250}, {name: "Mars", date: "2018-07-01", amt: 250}, {name: "Joe", date: "2018-07-02", amt: 250}, {name: "Saturn", date: "2018-07-01", amt: 250}, {name: "Joe", date: "2018-07-02", amt: 250}, {name: "Jupiter", date: "2018-07-01", amt: 250}]

    var data = [
    {name:"Joe", date:'2018-07-01', amt:250 },
    {name:"Mars", date:'2018-07-01', amt:250 },
    {name:"Joe", date:'2018-07-02', amt:250 },
    {name:"Saturn", date:'2018-07-01', amt:250 },
    {name:"Joe", date:'2018-07-02', amt:250 },
    {name:"Jupiter", date:'2018-07-01', amt:250 },
    ]
    var resArr = [];
    data.filter(function(item){
      var i = resArr.findIndex(x => (x.name == item.name && x.date == item.date && x.amt == item.amt));
      if(i <= -1){
            resArr.push(item);
      }
      return null;
    });
    console.log(resArr)
    
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Playground
    • Snippets
    • Cookbooks
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.