'How to map and filter through array based on a value?

How do i filter the data based on the id? Example if i wanted to filter id= "24". So it will filter out the object that is matching.

[
  {
    "id": "Sheet1",
    "data": [
      {
        "id": "24",
        "title": "Title of article",
        "date_time": "11/05/2022",
        "description": "Description of Article"
      },
      {
        "id": "25",
        "title": "Title of article 2",
        "date_time": "15/05/2022",
        "description": "Description of Article 2"
      }
    ]
  }
]

Output:

"data": [
      {
        "id": "24",
        "title": "Title of article",
        "date_time": "11/05/2022",
        "description": "Description of Article"
      }
    ]




Solution 1:[1]

I try this and i got the same output :

let arr = arrays.filter(array => array.id === "Sheet1");
let data = arr[0].data;
let result = data.filter(obj => obj.id === "24")
console.log(result)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 sabdahtb