简体   繁体   中英

Hash operations in array of the hashes - Angularjs

I have an array with having following elements:

$scope.users = [{"id": "1", "name": "Jai Rajput"}, {"id":"2", "name": "Nakul Sharma"}, {"id": "3", "Name": "Lovey Rajput"}]

Now I want to perform an update and delete in the shortest way on this Array .

Both operations can be made with Array#find function.

 let $scope = {}; $scope.users = [{"id": "1", "name": "Jai Rajput"}, {"id":"2", "name": "Nakul Sharma"}, {"id": "3", "Name": "Lovey Rajput"}]; $scope.users.find(v => v.id == 1).name = "Jai Kumar Rajput"; $scope.users.splice($scope.users.indexOf($scope.users.find(v => v.id == 3)), 1); console.log($scope.users); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM