我有一个包含以下元素的数组:
$scope.users = [{"id": "1", "name": "Jai Rajput"}, {"id":"2", "name": "Nakul Sharma"}, {"id": "3", "Name": "Lovey Rajput"}]
现在,我想以最短的方式在此update
上执行delete
和Array
。
答案 0 :(得分:1)
可以使用Array#find
函数进行这两项操作。
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);