This is no problem, but I am curious how I can rewrite this
“`
(function() {
var anchors = document.querySelectorAll(‘.subnav a’),
current = window.location.href;
for (var i = 0; i < anchors.length; i++) {
if (current.indexOf(anchors[i].href) != -1) {
anchors[i].classList.add(“active”);
}
}
})();
To something with “forEach” instead (like this pseudocode):
“`
(function() {
var anchors = document.querySelectorAll(‘.subnav a’),
current = window.location.href;
forEach(anchors.href) {
if (current.indexOf(anchors.href)) {
anchors.classList.add(“active”);
}
}
})();
Of course the above code is wrong, but I am trying to understand Javascript, so all input is welcome.
BTW, the search function in