how can i find an object from an array [ i want to find findIt object from cartItem ]

Viewed 28
const findIt = {
    productId: "htm-45",
    attribute: [
        {name:"size",index:2},
        {color:"red",index:2}
    ]
}

const cartItem = [
    {
        productId: "htm-45-34",
        atrributeId:"_672349e",
        attribute: [
            {name:"size",index:1}
        ]
    },
    {
        productId: "htm-45",
        attribute: [
            {name:"size",index:2},
            {name:"size",index:3},
        ]
    },
    {
        productId: "htm-45",
        attribute: [
            {name:"size",index:2},
            {color:"red",index:2}
        ]
    }
    
]
1 Answers
const idToSearch="htm-45"
const findIt = cartItem.find((item)=>item.productId===idToSearch)

Go through MDN docs

Related