散列数组中的散列操作 - Angularjs

时间:2017-05-04 10:07:56

标签: javascript angularjs arrays hash

我有一个包含以下元素的数组:

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

现在,我想以最短的方式在此update上执行deleteArray

1 个答案:

答案 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);