Removing empty strings from array

Benchmark created on


Setup

var arr = ['', 'foo', '', 'bar', '', '', 'baz', '', ''];

Test runner

Ready to run.

Testing in
TestOps/sec
Array.filter
arr = arr.filter(String);
ready
For loop
var len = arr.length, i = 0;

for (i; i < len; i++) {
  if (arr[i] === '') {
    arr.splice(i, 1);
    i -= 1;
  }
}
ready

Revisions

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