I am working with an AngularJS model that looks like this:
$scope.Model = {
Users : [{
UserId: '',
FirstName: '',
LastName: ''
}],
Products :[{
ProductId: '',
Price: ''
}]
};
Suppose I populate the 'Users' array with N users, and one of them has id=1
. How can I update the 'LastName' property for that specific user (with id=1
)?
If I receive a new AngularJS model as follows:
$scope.UserToUpdate ={
UserId: 1,
LastName: "Smith"
};
I need to iterate through the $scope.Model
array in order to find and update the user with id=1
, focusing only on changing the FirstName
property.
Keep in mind that the target user object may be located at any position within the array, such as $scope.Model.Users[0]
, $scope.Model.Users[1]
, $scope.Model.Users[10]
, or even at $scope.Model.Users[N]
.