angularjs forEach and splice

后端 未结 6 1270
梦如初夏
梦如初夏 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 19:07

    I haven't tried this with AngularJs, but with Angular 4 a similar way of this works pretty well.

    angular.forEach($scope.emails, function(email){
     if(email.value ===""){
       $scope.emails.splice($scope.emails.indexOf(email), 1);
     } 
    
    });
    

    Angular 4 version:

    this.emailArray.forEach(email => {
      if (email.value == "") {
        this.emailArray.splice(this.emailArray.indexOf(email),1);
      }
    });
    

提交回复
热议问题