Quick conditional removal of trailing slash

Benchmark created on


Setup

let slug = 'foo/';

Test runner

Ready to run.

Testing in
TestOps/sec
replace()
slug = slug.replace(/\/$/, '');
ready
endsWith() + slice()
if (slug.endsWith('/')) slug = slug.slice(0,-1);
ready
trimEnd()
slug = slug.trimEnd();


ready

Revisions

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