Issue #2099599 by jantimon: Minor for-loop optimizations for base.js.

PR for https://github.com/backdrop/backdrop-issues/issues/211