Last active
August 29, 2015 14:26
-
-
Save afaulkinberry/f51909563c6a6390184c to your computer and use it in GitHub Desktop.
AngularJS - New array from object array based on property value
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$scope.sortedArr = function(prop, propVal, masterArr){ | |
var newArr = []; | |
angular.forEach(masterArr, function(value, key) { | |
if(angular.equals(value[prop], propVal)){ newArr.push(value); } | |
}); | |
return newArr; | |
}; | |
var objArr = [ | |
{ "first_name" : "George", "last_name" : "Washington" }, | |
{ "first_name" : "John", "last_name" : "Adams" }, | |
{ "first_name" : "George", "last_name" : "Harrison" }, | |
{ "first_name" : "John", "last_name" : "Mellancamp" }, | |
{ "first_name" : "George", "last_name" : "Jetson" }, | |
{ "first_name" : "John", "last_name" : "Bravo" } | |
]; | |
var fNameArr = $scope.sortedArr('first_name', 'George', objArr); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment