Skip to content

Instantly share code, notes, and snippets.

@mannuelf
Created January 1, 2017 19:36
Show Gist options
  • Save mannuelf/083fc747488259616c7066bfdbeec97e to your computer and use it in GitHub Desktop.
Save mannuelf/083fc747488259616c7066bfdbeec97e to your computer and use it in GitHub Desktop.
filtering on an array
const products = [
{ name: 'cucumber', type: 'vegetable' },
{ name: 'banana', type: 'fruit' },
{ name: 'celery', type: 'vegatable' },
{ name: 'orange', type: 'fruit' },
];
let filteredProducts = [];
/*
for (var i = 0; i < products.length; i++) {
if (products[i].type === 'fruit') {
filteredProducts.push(products[i]);
}
}
*/
products.filter(function(product) {
return product.type === 'fruit';
});
filteredProducts;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment