foreachvfilter

Benchmark created on


Setup

const categoryProducts = [
  { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
    { name: 'Product 1', soldOut: false },
  { name: 'Product 2', soldOut: true },
  { name: 'Product 3', soldOut: false },
  { name: 'Product 4', soldOut: true },
  
];

Test runner

Ready to run.

Testing in
TestOps/sec
foreach
const oosProducts = [];
const inStockProducts = [];
                                    categoryProducts.forEach((product) =>
                                        product.soldOut ? oosProducts.push(product) : inStockProducts.push(product)
                                    );
const finalProducts = [...inStockProducts, ...oosProducts];
ready
filter
const inStockProducts = categoryProducts.filter(product => !product.soldOut);
const oosProducts = categoryProducts.filter(product => product.soldOut);

const finalProducts = inStockProducts.concat(oosProducts);
ready
for of
const oosProducts = [];
const inStockProducts = [];

for (const product of categoryProducts) {
  if (product.soldOut) {
    oosProducts.push(product);
  } else {
    inStockProducts.push(product);
  }
}

const finalProducts = inStockProducts.concat(oosProducts);
ready

Revisions

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