Get highest zIndex from all elements (v2)

Revision 2 of this benchmark created by A1r on


Preparation HTML

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>

Test runner

Ready to run.

Testing in
TestOps/sec
Vanilla js
var zIndex = Math.max.apply(null, [].map.call(document.querySelectorAll('*'), function(el) {
  return parseInt(el.style.zIndex, 10);
}));
ready
Vanilla js 2
var zIndex = Math.max.apply(null, Array.prototype.map.call(document.querySelectorAll('*'), function(el) {
  return +el.style.zIndex;
}));
ready
jQuery
var zIndex = Math.max.apply(null, $.map($('*'), function(e, n) {
  return parseInt($(e).css('z-index'), 10);
}));
ready
jQuery 2
var index_highest = 0;
$("*").each(function() {
  var index_current = parseInt($(this).css("zIndex"), 10);
  if (index_current > index_highest)
    index_highest = index_current;
});
ready
Vanilla js 3
var index_highest = 0;
Array.prototype.forEach.call(document.querySelectorAll('*'), function(item) {
  var index_current = parseInt(item.style.zIndex, 10);
  if (index_current > index_highest)
    index_highest = index_current;
});
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.