There are (at least) two approaches to this problem. You can chain prevAll() and nextAll() into slice(), then use add() to combine the two sets:
var $active = $("li.active");
var $around = $active.prevAll().slice(0, 2)
.add($active.nextAll().slice(0, 2));
Or you can fetch the index() of the active element, use slice()
to get siblings around that index, then filter the active element out with not():
var $active = $("li.active");
var activeIndex = $active.index();
var $around = $active.siblings().addBack()
.slice(Math.max(0, activeIndex - 2), activeIndex + 3)
.not($active);