Reputation: 4967
Can anybody tell how to search for a string in all properties. If match in some property I need to push the object in array in AngularJS.
I have an array
$scope.ListOfPeople = [
{ PersonID: 10, FirstName: "John", LastName: "Smith", Sex: "Male" },
{ PersonID: 11, FirstName: "James", LastName: "Last", Sex: "Male" },
{ PersonID: 12, FirstName: "Mary", LastName: "Heart", Sex: "Female" },
{ PersonID: 13, FirstName: "Sandra", LastName: "Goldsmith", Sex: "Female" },
{ PersonID: 14, FirstName: "Shaun", LastName: "Sheep", Sex: "Male" },
{ PersonID: 15, FirstName: "Nicola", LastName: "Smith", Sex: "Male" }
];
If the user types some value in search textbox. I need to search with PersonID, FirstName, LastName, Sex with all properties if it is match need to push the matched object.
Upvotes: 0
Views: 722
Reputation:
Something like that ?
for(var index in $scope.ListOfPeople) {
if ($scope.ListOfPeople.hasOwnProperty(index)) {
if($scope.ListOfPeople[index] == "Your string") {
// Do something here
}
}
}
Upvotes: 0