Get last character from string

Benchmark created by ryanve on


Setup

function f1(str) {
      return str.charAt(str.length - 1);
  }
  function f2(str) {
      return str[str.length - 1];
  }

Test runner

Ready to run.

Testing in
TestOps/sec
charAt
f1('some-string');
ready
string array value
f2('some-string');
ready

Revisions

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