How to target only first and last intersected elements with Intersection Observer?

Something like

 if (entry.isIntersecting) {
        if(entry.isIntersecting[0]) {
// do your thing
 }
}