Broadway is an avenue in the New York City borough of Brooklyn that extends from the East River in the neighborhood of Williamsburg in a southeasterly direction to East New York for a length of 4 miles .