Limbo
Limbo

Reputation: 13

Replace JSON Values in Angular

My question is the following. I have a JSON Object in Angular and I want to replace all ";" with "" from a specific key.

$scope.users = data; 

In this case I want to run a loop and replace the values only in

$scope.users[i]['pic'];

Thank you in advance

Upvotes: 1

Views: 4032

Answers (2)

user2036241
user2036241

Reputation:

$scope.users = [{"uid":"295","pic":"picsprofileIcon.png;"},{"uid":"295","pic":"picsprofileIcon.png;"}]

for(i in $scope.users){ 
    $scope.users[i]['pic'] = $scope.users[i]['pic'].replace(";", "");    
}

Upvotes: 0

micha
micha

Reputation: 1238

$scope.users=[{'pic':'df;gd;'},{'pic':'adfgadfgadfgad;adf   fdag;'},{'pic':'adfdff; ;;;'}];


angular.forEach($scope.users,function(value, key) {
value.pic= value.pic.replace(/;/g ,'');
},{});

http://jsfiddle.net/fp5roLae/

Upvotes: 1

Related Questions