0

This is my code

$scope.search={"className":{"Id":"101","Class":"business"}};

The above data coming from another control,now i'm accessing Class property like $scope.search.className.Class; , But i want convert property Class to lowercase like $scope.search.className.class; in angularjs only.

  • possible duplicate of [How to parse JSON to object with lower case key](http://stackoverflow.com/questions/14697352/how-to-parse-json-to-object-with-lower-case-key) – Vineet Sep 03 '15 at 05:25
  • http://stackoverflow.com/questions/12539574/whats-the-best-way-most-efficient-to-turn-all-the-keys-of-an-object-to-lower –  Sep 03 '15 at 05:27

1 Answers1

1

You may be able to achieve it by iterating over the entire object and writing a function to convert all properties to lowercase :

for(var prop in obj){
    //Make a new property name with lowercase
    obj[prop.toLowerCase()]=a[s];
    //delete the original property with uppercase name
    delete a[s];
}

Keep in mind this will not behave correctly if you have property names in your object with just the case difference like : {foo:"bar",Foo:"baz"}

Sambhav Gore
  • 555
  • 2
  • 13