Filter out object section that the button is attached to

I am having trouble filtering out objects in an array. The code I have when one button is clicked on the whole array is filtered. I want to where I clicked, that object is deleted from the array. I have tried the splice, and filtering methods but I end up with the same results as the whole array gets deleted instead of that one item. How can I target just that one item?

function removeItem(btns, id) {

    btns.forEach(btn => {
        btn.addEventListener('click', (e) => {

            let newArr = shoppingList.filter((item, i) => {
                return item.id !== item.id
            })

            shoppingList = newArr
            cartMenuItems.innerHTML = newArr
            cartItemCount.innerText = newArr.length
            return newArr
        })
    })
}

6 thoughts on “Filter out object section that the button is attached to”

  1. 27026 619809magnificent submit, very informative. I ponder why the opposite experts of this sector dont realize this. You need to proceed your writing. Im confident, youve a great readers base already! 653415

    Reply

Leave a Comment