I have an array as follows:
const array = [
{id: 3, amount: 100, productId: 10, title: "Color/Red", variantChildren: Array(0)},
{id: 4, amount: 5, productId: 10, title: "Color/Green", variantChildren: Array(2)},
{amount: 0, variantChildren: {…}, title: "Color/Red"},
{amount: 0, variantChildren: {…}, title: "Color/Green"},
{amount: 0, variantChildren: {…}, title: "Color/Purple"}
]
I need to remove the duplicates that have the amount of 0. I'm trying to figure out how to do this with .filter() or .forEach()
So items [2] & [3] would get removed, and returned with a new array:
const newArray = [
{id: 3, amount: 100, productId: 10, title: "Color/Red", variantChildren: Array(0)},
{id: 4, amount: 5, productId: 10, title: "Color/Green", variantChildren: Array(2)},
{amount: 0, variantChildren: {…}, title: "Color/Purple"}
]
console.log(JSON.stringify(objToLog, null, 2)). Otherwise, we have to wade through comments complaining about syntax where we just don't need to.title, remove the ones that have amount 0?