【问题标题】:Hash operations in array of the hashes - Angularjs哈希数组中的哈希操作 - Angularjs
【发布时间】:2017-10-02 10:57:32
【问题描述】:

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

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

现在我想在这个Array 上以最短的方式执行updatedelete

【问题讨论】:

  • 好的。你自己尝试过什么?
  • 看起来像家庭作业。

标签: javascript angularjs arrays hash


【解决方案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);

【讨论】:

    猜你喜欢
    • 2017-01-16
    • 2014-04-18
    • 2011-04-20
    • 1970-01-01
    • 2020-07-19
    • 2021-02-05
    • 2014-05-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多