Preview:
var loc = 2;
for(var i=1; i<=4; i++){
    if(i==loc){
        $('#menu'+i).addClass('active');
    }else{
        $('#menu'+i).removeClass('active');
    }
}

<li class="nav-item" id="menu2"><a class="nav-link" href="ordersToBePlaced">Orders</a></li>
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter