javascript encoding special characters code example
Example 1: javascript html special characters
return mystring.replace(/&/g, "&").replace(/>/g, ">").replace(/</g, "<").replace(/"/g, """);
Example 2: html escape function javascript
function escapeHTML(text) {
var replacements= {"<": "<", ">": ">","&": "&", """: """};
return text.replace(/[<>&"]/g, function(character) {
return replacements[character];
});
}
Example 3: jq unencode string
# -r enable raw output
jq -r .[0].string FILE.json