Get a number from a class of a HTML element
You might use something like the snippet below, that is:


sure a bit shorter
probably faster, because:


using find() rather than filter() makes the loop stop as soon as the desired result is got
looking for the involved class-prefix and extracting the number are both processed in the same statement

and browser agnostic, while includes() is not recognized by IE




function get_gallery_columns($el) {
  var matches, result = false;
  $el.attr('class').split(/\s+/).find(function (className) {
    if (matches = className.match(/^gallery-columns-(\d+)$/)) {
      result = +matches[1];
      return true;
    }
  });
  return result;
}

console.log(get_gallery_columns($('#gallery-1')));
&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"&gt;&lt;/script&gt;
&lt;div id="gallery-1" class="gallery galleryid-555 gallery-columns-3 gallery-size-thumbnail"&gt;
    ...
&lt;/div&gt;