Alternative for `some` method in NodeList
15:38 09 Mar 2022

I have a simple question, what simplest method do you know to replace the method some for NodeList? This some method is only for Array prototype.

I have currently come up with the rather outlandish idea of iterating and holding a boolean in a variable, however I would like to know your point of view.

My obscure approach

const toCheck = (elem) => elem.checked;

const methodSome = (list, fn) => {
  let result = false;
  for (let i = 0; i < list.length; i++) {
    if (fn(list[i])) {
      result = true;
      break;
    }
  }
  return result;
};

const elems = document.querySelectorAll(`[name="something"]`);

const hasBeenChecked = methodSome(elems, toCheck);

javascript