For

Benchmark created on


Description

Bla bla

Setup

const items = [4, 'str', undefined, false, 6];

Test runner

Ready to run.

Testing in
TestOps/sec
For array
const newItems = [];
for(let i = 0; i<= items.length; i++){
  if(items[i]){
  	newItems.push({value: items[i]});
  }
}
ready
Reduce
const newItems = items.reduce((allItems, item) => {
  if(item){
  	return [...allItems, {value: item }];
  }
  return allItems
}, [])
ready
Filter-Map
const newItems = items.filter(item => !!item).map(item => ({ value: item }));
ready

Revisions

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