How to convert string to array in angularJS
You should use JSON.parse()
to create an array:
let str = '[{\"name\":\"title\",\"value\":\"%post_title%\"},{\"name\":\"author\",\"value\":\"%author_name%\"}]';console.log(JSON.parse(str));
.as-console-wrapper { max-height: 100% !important; top: 0; }
You can use JSON.parse for that.
const myNewArray = JSON.parse(str);
use angular.fromJson()
$scope.x = '[{\"name\":\"title\",\"value\":\"%post_title%\"},{\"name\":\"author\",\"value\":\"%author_name%\"}]'; console.log(angular.fromJson($scope.x));
otherwise use JSON.parse()
console.log(JSON.parse($scope.x));