angularjs forEach and splice

后端 未结 6 1196
梦如初夏
梦如初夏 2021-02-01 18:23

I have an array like this:

$scope.emails = [
  {\"key\":\"Work\",\"value\":\"user@domine.com\"},
  {\"key\":\"\",\"value\":\"\"},
   {\"key\":\"Work\",\"value\":         


        
6条回答
  •  情话喂你
    2021-02-01 18:54

    indexOf returns -1 when it doesn't find an item.

    A way to remove an item, and to avoid removing the last one when not found, is:

    var index = $scope.items.indexOf($scope.oldItem);
    
    if (index != -1) {
      $scope.items.splice(index, 1);
    }
    

提交回复
热议问题