Last Array Element (v7)

Revision 7 of this benchmark created on


Setup

var arr = [];
  var elems = Math.floor(Math.random() * 70 + 5);
  for (var i = 0; i < elems; i++) {
    arr.push(i);
  }

Test runner

Ready to run.

Testing in
TestOps/sec
.length-1
var last = arr[arr.length - 1];
ready
slice(-1)[0]
var last = arr.slice(-1)[0];
ready
Push-Pop
var last;
arr.push(last = arr.pop());
ready
Control (elems pre-cached)
var last = arr[elems-1];
ready
reverse()[0]
var last = arr.reverse()[0];
ready

Revisions

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