gpt4 book ai didi

javascript - 哈希数组中的哈希运算 - Angularjs

转载 作者:行者123 更新时间:2023-12-03 04:25:03 24 4
gpt4 key购买 nike

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

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

现在我想以最短的方式对此数组执行更新删除

最佳答案

这两种操作都可以使用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);

关于javascript - 哈希数组中的哈希运算 - Angularjs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43779891/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com