1

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

5
  • Could you provide your JSON code? Commented Jan 21, 2015 at 22:55
  • {"uid":"295","username":"xxx","password":"1234","email":"[email protected]","usertype":"3","profilePic":"pics\/profileIcon.png;"} Commented Jan 21, 2015 at 22:58
  • So you would like "pics\/profileIcon.png;" to be changed to "pics\/profileIcon.png"? Commented Jan 21, 2015 at 23:00
  • What does this have to do with Angular? Commented Jan 21, 2015 at 23:01
  • exactly!For all the strings in my JSON Object Commented Jan 21, 2015 at 23:02

2 Answers 2

1
$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/

Sign up to request clarification or add additional context in comments.

Comments

0
$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(";", "");    
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.