Skip to content

Instantly share code, notes, and snippets.

@bora89
Created January 5, 2017 14:53
Show Gist options
  • Select an option

  • Save bora89/2bea2d3f428df41e5353c4100603cafd to your computer and use it in GitHub Desktop.

Select an option

Save bora89/2bea2d3f428df41e5353c4100603cafd to your computer and use it in GitHub Desktop.
app.filter('startsWithA', function () {
// function to invoke by Angular each time
// Angular passes in the `items` which is our Array
return function (items) {
// Create a new Array
var filtered = [];
// loop through existing Array
for (var i = 0; i < items.length; i++) {
var item = items[i];
// check if the individual Array element begins with `a` or not
if (/a/i.test(item.name.substring(0, 1))) {
// push it into the Array if it does!
filtered.push(item);
}
}
// boom, return the Array after iteration's complete
return filtered;
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment