how to filter and get limit amount of data using javascript

I have an array which contains some java script objects and I am using ejs for display data but the problem is – that I have to filter that data in the bases of req.params.id and want to next 2 data objects..! after filtering data — please help

my code is –

app.get("/:id", (req, res) => {
  const requestParams = _.lowerCase(req.params.id);

  let obj = blogData.find((o) => o.heading >= "Yoga-During-COVID");
  console.log(obj);
 
  blogData.forEach(function (post) {
    const storedTitel = _.lowerCase(post.heading);
    
    if (storedTitel === requestParams) {
      res.render("blogfullDetail", {
        date: post.date,
        heading: post.heading,
        subheading: post.subheading,
        discription: post.discription,
        discription2: post.discription2,
        author: post.author,
        authorImage: post.authorImage,
        mainImg: post.mainImg,
      });
    }
  });

}); 

data file –

enter image description here

Answer

Use a combination of findIndex and slice. findIndex returns the index of the matching element and slice returns a sub-array from that index to a computed higher index…

let blogData = [{
    id: 1,
    title: 'yoga is good'
  },
  {
    id: 32,
    title: 'yoga helps you stretch'
  },
  {
    id: 12,
    title: 'covid yoga is good too'
  },
  {
    id: 41,
    title: 'no such thing as too much yoga'
  },
  {
    id: 57,
    title: 'is hot yoga too hot'
  }
];

// say you need the post about covid...
let targetTitle = 'covid yoga is good too';
let index = blogData.findIndex(p => p.title === targetTitle);

// with the index, answer a slice of the blogs
// starting at that index, ending 3 later
let posts = blogData.slice(index, index + 3);
console.log(posts)