JSFiddle - React, Tailwind, and code Playground
by vasi_32
JavaScript
var arr = [{
type_id: "3",
full_empty: "true",
quantity: 1
}, {
type_id: "3",
full_empty: "true",
quantity: 1
}, {
type_id: "9",
full_empty: "true",
quantity: 4
}, {
type_id: "9",
full_empty: "false",
quantity: 4
}, {
type_id: "9",
full_empty: "true",
quantity: 4
}, {
type_id: "9",
full_empty: "true",
quantity: 4
}, {
type_id: "9",
full_empty: "true",
quantity: 4
}];
var newArray = [];
arr.forEach(function(item) {
if (newArray.length !== 0) {
var _isPresent = newArray.find(function(secItem) {
return secItem.type_id === item.type_id && secItem.full_empty === item.full_empty
})
if (_isPresent == undefined) {
newArray.push(item)
}
} else {
newArray.push(item)
}
})
console.log(newArray)