Within my javascript arraylist, I am currently storing the following elements:
list = [
{header: "header1", code: ""},
{label: "label1", price: 10},
{header: "header2", code: ""},
{header: "header3", code: ""},
{header: "header4", code: ""}
]
My question is how can I filter the array to retrieve only the first 2 occurrences of the element "header"?
The expected output would be:
list = [
{header: "header1", code: ""},
{label: "label1", price: 10},
{header: "header2", code: ""}
]
I'm looking for a feasible and efficient solution to achieve this using javascript.