I'm having trouble filtering a JSON array. Here's an example of what my JSON array looks like:
vm.users = [{ "fname": "Antoan", "lname": "Jonson", "Address": "Address1" }, ... ]
How do I filter by last name starting with a specific term (e.g. 'Jo')? I've tried the following code snippet:
angular.module('MyApp', ['ngMaterial', 'ngMessages', ])
.controller('AdminController', function ($scope, $http, $filter, $location, $sce) {
MyApp.filter('myFilter', function () {
return function (input, term) {
var output = [];
angular.forEach(input, function (value, index) {
if (value.lname.startsWith(term)) {
output.push(value);
}
});
return output;
}
});
});