Get last character from string (v2)

Revision 2 of this benchmark created by Kim on


Setup

function charAt(str) {
      return str.charAt(str.length - 1);
  }
  function index(str) {
      return str[str.length - 1];
  }
  function slice(str) {
      return str.slice(-1);
  }
  function substr(str) {
      return str.substr(-1);
  }

Test runner

Ready to run.

Testing in
TestOps/sec
charAt
charAt('some-string');
ready
string array value
index('some-string');
ready
slice
slice('some-string');
ready
substr
substr('some-string');
ready

Revisions

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