-1
{
  "GetAllcar": [{
    "cars_id": "1",
    "user_id": "7",
    "car_name": "Maruti Suzuki Swift",
    "car_brand": "Maruti Suzuki",
    "price": "50000",
    "year": "2017",
    "kilometer": "8047",
    "fuel_type": "Diesel",
    "transmission": "Manual",
    "color": "Grey",
    "insurance": "Not Available",
    "seller_type": "1st",
    "available_at": "Salt Lake, Kolkata",
    "reg_city": "Kolkata",
    "image": "BPYZGCY_1158520_1_8695497.jpeg",
    "ucarengine": "2967",
    "ucarpower": "262",
    "ucarmilage": "137"
  }, {
    "cars_id": "22",
    "user_id": "7",
    "car_name": "Maruti Suzuki Swift",
    "car_brand": "Maruti Suzuki",
    "price": "555000",
    "year": "2015",
    "kilometer": "54854",
    "fuel_type": "Diesel",
    "transmission": "Manual",
    "color": "White",
    "insurance": "Comprehensive",
    "seller_type": "First User",
    "available_at": "Kolkata",
    "reg_city": "Kolkata",
    "image": "Suzuki-Swift-Widescreen.jpg",
    "ucarengine": "1248",
    "ucarpower": "74",
    "ucarmilage": "23"
  }, {
    "cars_id": "24",
    "user_id": "7",
    "car_name": "Ferrari 488",
    "car_brand": "Ferrari",
    "price": "9999999",
    "year": "2016",
    "kilometer": "3605",
    "fuel_type": "Diesel",
    "transmission": "Automatic",
    "color": "Blu Tour De France",
    "insurance": "Comprehensive",
    "seller_type": "First User",
    "available_at": "New Town, Kolkata",
    "reg_city": "Kolkata",
    "image": "Ferrari-488-Right-Front-Three-Quarter-61997 .jpg",
    "ucarengine": "3902",
    "ucarpower": "660",
    "ucarmilage": "8"
  }, {
    "cars_id": "25",
    "user_id": "7",
    "car_name": "Lamborghini Huracan",
    "car_brand": "Lamborghini",
    "price": "8800000",
    "year": "2015",
    "kilometer": "5607",
    "fuel_type": "Diesel",
    "transmission": "Automatic",
    "color": "Bianco Canopus",
    "insurance": "Not Available",
    "seller_type": "First User",
    "available_at": "Mumbai",
    "reg_city": "Mumbai",
    "image": "Lamborghini-Hurcan-Right-Side-30064 .jpg",
    "ucarengine": "5204",
    "ucarpower": "631",
    "ucarmilage": "8"
  }, {
    "cars_id": "26",
    "user_id": "7",
    "car_name": "BMW Z4",
    "car_brand": "BMW",
    "price": "4850000",
    "year": "2013",
    "kilometer": "69045",
    "fuel_type": "Petrol",
    "transmission": "Manual",
    "color": "Sparking Brown",
    "insurance": "Comprehensive",
    "seller_type": "First User",
    "available_at": "Salt Lake, Kolkata",
    "reg_city": "Kolkata",
    "image": "BMW-Z4-Left-Front-Three-Quarter-21982_l .jpg",
    "ucarengine": "2979",
    "ucarpower": "302",
    "ucarmilage": "10"
  }, {
    "cars_id": "28",
    "user_id": "9",
    "car_name": "Alto 800",
    "car_brand": "Maruti Suzuki",
    "price": "80000",
    "year": "2016",
    "kilometer": "15090",
    "fuel_type": "Diesel",
    "transmission": "Manual",
    "color": "Red",
    "insurance": "Not Available",
    "seller_type": "First User",
    "available_at": "Chennai",
    "reg_city": "Chennai",
    "image": "1_Maruti-Alto-800-2016.jpg",
    "ucarengine": "1500",
    "ucarpower": "565",
    "ucarmilage": "19"
  }, {
    "cars_id": "29",
    "user_id": "9",
    "car_name": "Bugatti Veyron",
    "car_brand": "Bugatti",
    "price": "10000000",
    "year": "2016",
    "kilometer": "8",
    "fuel_type": "Petrol",
    "transmission": "Automatic",
    "color": "Titanium Grey Metallic",
    "insurance": "Comprehensive",
    "seller_type": "First User",
    "available_at": "Bangalore",
    "reg_city": "Bangalore",
    "image": "Bugatti-Veyron-Right-Front-Three-Quarter-52786_ol.jpg",
    "ucarengine": "7993",
    "ucarpower": "987",
    "ucarmilage": "4"
  }]
}

The above is my Json response. I want to remove fuel_type duplicate value. How can I do that. Thanks in advance

Serge K.
  • 5,303
  • 1
  • 20
  • 27
Jon B
  • 1
  • 6
  • what is a *duplicate*? – Nina Scholz Sep 06 '17 at 07:54
  • 2
    Possible duplicate of [Remove Duplicate objects from JSON Array](https://stackoverflow.com/questions/23507853/remove-duplicate-objects-from-json-array) – Ferus7 Sep 06 '17 at 07:56
  • you have 7 json objects in GetAllCar{}. Out of which 5 have Diesel as a fuel_type and 2 have Petrol as fuel_type. Do you want 1 out if 5 and 1 out of 2, is that what you mean by remove duplicates ? – Ankush Rathi Sep 06 '17 at 07:58

1 Answers1

0
Array.prototype.removeRepeatAttr = function() {
    var tmp = {}, a = this.slice(); 
    for(var i = j = 0; i < a.length; i++) {
        if(!tmp[a[i].id]) {
            tmp[a[i].id] = !0;
            j++;
        }
        else {
            this.splice(j, 1);
        }
    };
}
Koopakiller
  • 2,838
  • 3
  • 32
  • 47