Home > Enterprise >  How can I replace string values in Angular
How can I replace string values in Angular

Time:09-14

I currently have a string value as follows:

"{"rows":[{"columns":[{"styleClass":"col-md-3"},{"styleClass":"col-md-3"},{"styleClass":"col-md-3"},{"styleClass":"col-md-3"}]},{"columns":[{"styleClass":"col-md-6"},{"styleClass":"col-md-6"}]}]}"

How can I replace every styleClass keyword with Class to change it to:

"{"rows":[{"columns":[{"Class":"col-md-3"},{"Class":"col-md-3"},{"Class":"col-md-3"},{"Class":"col-md-3"}]},{"columns":[{"Class":"col-md-6"},{"Class":"col-md-6"}]}]}"

CodePudding user response:

It does not work because u have duble quotes inside double quotes

let incial = '{"rows":[{"columns":[{"styleClass":"col-md-3"},{"styleClass":"col-md-3"},{"styleClass":"col-md-3"},{"styleClass":"col-md-3"}]},{"columns":[{"styleClass":"col-md-6"},{"styleClass":"col-md-6"}]}]}';
let replaced = incial.replaceAll("styleClass","Class");
console.log(replaced);

  • Related