Convert a javascript object into JSON string format

Today in this blog, we are going to learn about the javascript object and how can we convert any Convert a JavaScript object into JSON string format javascript object into JSON.

Convert a JavaScript object into JSON string formatexpoundsofttechsolution Convert a JavaScript object into JSON string format

With this angular.toJson API function, we can convert a javascript object into JSON string format.

<!DOCTYPE html>
<html>
   <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>
   <body>
      <div ng-app="App" ng-controller="myController">
         <p>orignal text: {{ a }}</p>
         <p>result: {{ b }}</p>
      </div>
      <script>
         var t = angular.module('App', []);
         t.controller('myController', function($scope) {
              $scope.a = "Angular";
              $scope.b = angular.toJson($scope.a);
         
         });
      </script>
   </body>
</html>

Original text: Angular

result: “Angular”

So, thanks for following this blog, and if you need any help please leave your queries in the comment box we will be happy to help you.